In: Computer Science
Number Analysis Program (Specific Design Specifications)
Design a Python program that asks the user to enter a series of 20 numbers. The program should store the numbers in a list then display the following data: The lowest number in the list The highest number in the list The total of the numbers in the list The average of the numbers in the list
This python program must include the following functions. Your program must use the exact names, parameter lists, and follow the function descriptions provided.
def CreateNumberList(howMany): This function will accept a parameter for how many numbers to include in a list. It will create a list containing howMany elements that are random numbers in the range 1 - 500. The function return value will be the list that contains these values.
def SortList(myList): This function will accept the list of random numbers as the parameter variable. It will first use the sort() function to sort the values in the list. Then this function will use index 0 and index len(myList) - 1 to print the smallest and largest value in the list. This function does not have a return value.
def DisplayAverage(myList): This function will accept the list of random numbers as the parameter variable. If will use a for loop to iterate through each item in the list and add each value to a sum variable. You will then calculate the average of the values and display the average as the output. This function does not have a return value.
def main(): This function will begin by asking the user how many numbers they want to generate in their list. You must include an input validation loop that will not accept a number less than 1. After the input is validated, call the CreateNumberList function and store the return value in a variable, then call the SortList and DisplayAverage functions passing your list as an argument. Call your main function to execute the program.
Answer : please up vote or comment for any query i will update the same .Thanks
Note : check attached image for program and output
Program compiled and run in Python 3
Program :
import random #import random number package
def CreateNumberList(howmany): #get input to generate random
number
List=[]
for x in range(howmany):#from 0 to howmany numbers
List.append(random.randint(1,65535)) #append one by one in
list
return List #return list
def SortList(myList):
myList.sort()#sort the list
print("Smallest Number in List is :",myList[0]) #smallest
number
print("Largest Number in List is :",myList[len(myList)-1]) #largest
number
def DisplayAverage(myList):
sum=0
for i in myList:
sum+=i
print("Sum of numbers in list : ",sum) #sum of all numbers
length = len(myList) #number of element in list
print("Average of list number: ",sum/length) #ger average
def main():
number=0
number =int( input("Enter numbers to generate: "))#get number from
user
while (number <1 or number >500): #check for number
input
number =int( input("Enter numbers to generate: "))
List=CreateNumberList(number)
print("List is: ",List)#print list number
SortList(List)
DisplayAverage(List)
if __name__ == '__main__':
main() #call main function
Output :
Program :