
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Fix the code below properly with no errors:
Module.py
#Defination to sort the list
def sort(listNum):
sortedList = []
#While loop will run until the listNum don't get null
while(len(listNum) != 0 ):
#Set the min as first element in list
min = listNum[0]
#iterate over the list to compare every element with num
for ele in listNum:
#If element is less than min
if ele < min:
#Then set min as element
min = ele
#append the sorted element in list
sortedList.append(min)
#Remove the sorted element from the list
listNum.remove(min)
return sortedList
#Function to find the sum of all elements in list
def SumOfList(listNum):
#Set the sum as zero
sum =0
#Iterate over the list to get every element
for ele in listNum:
#Keep adding the element to the sum variable
sum = sum + ele
#returnt the sum
return sum
#Function to find the max of the list
def listMax(listNum):
#To store the max
max =0
#Iterate over the list
for ele in listNum:
#If element is greater than max then max = element
if(ele>max):
max = ele
#Return the max
return max
***************************************************************************************
Main .py
#Import the module file having the 3 functions
import module
import random
def main():
#use the random module to create the list of random integers
#To store the random numbers in range 0 to 10
randomList = []
#Create the loop to create the list of 5 random integers
for i in range(0,5):
#Use randint to create the random integer
num = random.randint(0,10)
#Add the random integer into the list
randomList.append(num)
#Now create the menu to let user choose from what to perform on the random list
print("Random list created : ",randomList,"\nSpecify what operations you wanna perform on the list")
print("1:Sorting\n2:Sum of all elements \n3:Maximum\nChooce 1-3 : ",end = "")
#Now take input from the user
choice = int(input())
#Now use decision structures to decide which function to call from module.py
if(choice == 1 ):
#Print the sorted list
print("Sorted list as follows : " ,module.sort(randomList))
elif(choice == 2):
#Print the sum of all elements in list
print("The sum of all elements in list : ",module.SumOfList(randomList))
elif(choice == 3):
#print the maximum of list
print("The maximum of list is : ",module.listMax(randomList))
#When the __name__ will be ___main__ the main function will be called.
if __name__ == "__main__":
main()
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 3 images

Knowledge Booster
Similar questions
- The chapter is nested lists Create code in python using for loops Thanks!arrow_forwardwrite basic python code adn create a list list_append: adds a new element to the end of the list. then printarrow_forward**Cenaage Python** Question: A sequential search of a sorted list can halt when the target is less than a given element in the list. Modify the program to stop when the target becomes less than the current value being compared. In a sorted list, this would indicate that the target is not in the list and searching the remaining values is unnecessary. CODE: def sequentialSearch(target, lyst): """Returns the position of the target item if found, or -1 otherwise. The lyst is assumed to be sorted in ascending order.""" position = 0 while position < len(lyst): if target == lyst[position]: return position position += 1 return -1 def main(): """Tests with three lists.""" print(sequentialSearch(3, [0, 1, 2, 3, 4])) print(sequentialSearch(3, [0, 1, 2])) # Should stop at second position. print(sequentialSearch(3, [0, 4, 5, 6])) if __name__ == "__main__": main()arrow_forward
- python LAB: Subtracting list elements from max When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. Write a program that adjusts a list of values by subtracting each value from the maximum value in the list. The input begins with an integer indicating the number of integers that follow.arrow_forwardParallel Lists JumpinJive.py >- Terminal Summary 1 # JumpinJava.py - This program looks up and prints t and prices of coffee orders. 2 # Input: In this lab, you use what you have learned about parallel lists to complete a partially completed Interactive Python program. 3 # Output: Name and price of coffee orders or error if add-in is not found 4 The program should either print the name and price for a coffee add-in from the Jumpin' Jive 5 # Declare variables. Coffee Shop or it should print the message "Sorry, we do not carry that.". 6 NUM_ITEMS = 5 # Named constant 8 # Initialized list of add-ins 9 addIns = ["Cream", "Cinnamon", "Chocolate", "Amarett "Whiskey"] Read the problem description carefully before you begin. The data file provided for this lab includes the necessary input statements. You need to write the part of the program that searches for the name of the coffee add-in(s) and either prints the name and price of the add-in or prints 10 the error message if the add-in is not…arrow_forwardPut the following code in a main.py file and a module.py file. Define the names sort, list_max and sum_of_list after putting the code into a main file and a module file #predefined modules import random import math #function to sort the list in ascending order def sort(x): #predefined function sort() x.sort() #print the sorted list print("\nSorted list is: ",str(x)) #function to find the sum of list elements def sum_of_list(x): #predefined function sum() Sum=sum(x) #return the sum of list elements return Sum #function to list the maximum from the list def list_max(x): #predefined function max() maximum=max(x) #return maximum return maximum #function to test the above three function def main(): #set a flag variable flag=True #create a list list1=list() #initialize the list element by using randrange() predefined function of random module list1=[random.randrange(1, 50, 1) for i in range(0,7)] #print the…arrow_forward
- What are the instructions for creating lists?arrow_forwardWrite the code (Python) necessary to sum the elements of an list named: myLstAssume the list myLst has already been created and initializedAssume the constant SIZE has already been created and initialized with the number of elements in the myLst list.Complete the following tasks:Using a loop of your choice,OOutput each element of the list myLst•Calculate the sum of the elements of the list myLst. Create any variables necessary to complete this task.Output the string "Sum is: " followed by the actual sumNote: Only submit the code necessary to complete this task. Do not create myLst or SIZE, as you are to assume they have already beencreated and assigned values.arrow_forwardIN PYTHON THANK YOUarrow_forward
- O b. Remove the O. Remove the second element in the list O d. Remove the element before the last element in the list QUESTION 6 The following code inserts an element at the beginning of the list public void insertBegin(T e) { Node temp = new Node (e); head = temp; temp.Next = head; size++; } O True O False QUESTION 7 what does the following code do?arrow_forwardusing python in google colabarrow_forwardList comprehension. Write a Python program called list_comprehension.py that contains remove_list = [1,5,7, 9]. Create a list that is initialized by a list comprehension that contains all numbers from 0-10, but none of the numbers on the remove_list. Do not use for loop. Print the contents of the list.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY