1) What is the purpose of the code below?  2) What is each function used for in the code? 3) What are the names of the parameters/ arguments and what are they responsible for?  4) Why did you use a while loop in you code?  5) How did you accomplish the sort() to sort numbers? Code:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

1) What is the purpose of the code below? 

2) What is each function used for in the code?

3) What are the names of the parameters/ arguments and what are they responsible for? 

4) Why did you use a while loop in you code? 

5) How did you accomplish the sort() to sort numbers?

Code:

#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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education