Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Put 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 original list

    print("\nThe list element is shown below:\n" + str(list1))

    #repeatative strurure while

    while(flag):

        # print the menu

        print("\n******** Menu ********\n1. Sort the element\n2. Find the maximum from the list\n3. Find the sum of list element\n4. To exit the program")

        # input user choice

        ch = int(input("\nEnter your choice: "))

        #decision struture

        #if ch is 1

        if(ch==1):

            # sort the list

            sort(list1)

        #otherwise, if ch is 2

        elif(ch==2):

            # print the maximum from list

            print("\nMaximum from the list element is: ", list_max(list1))

        #otherwise, if ch is 3

        elif(ch==3):

            #print the sum of list

            print("\nSum of list element is: ",sum_of_list(list1))

        #otherwise

        else:

            flag=False

#function call

main()

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY