Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Using the code below, answer the following questions:

1) What are each of the 3 functions responsible for?

2) How many parameters will each function have?

3) What does each function return?

4) How will the program be controlled?

5) What functions will it call?

6) How will it communicate the results with the user? 

********************************************* Code starts here **************************************************

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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education