Question

In: Computer Science

Use Python to write the following code. Program Specifications: You are to design the following menu:...

Use Python to write the following code.

Program Specifications:

You are to design the following menu:

G] Get a number

S] Display current sum

A] Display current average

H] Display the current highest number

L] Display the current lowest number

D] Display all numbers entered

Q] Quit

If the user enters G, S, A, H, L, or D before selecting G the program needs to advise the user to go and enter a number first.

Rules for the Programmer (you)

  1. Source code must use a dynamic list to store all numbers
  2. Source code must have a function for each of the menu options above (I guess even for quit too]
  3. Source code must have reasonable comments
  4. Source code must not allow the user to do bad things (you can assume they will enter a number if they press G or if you want to figure it out, yell at the user if he or she does not enter a number)

Solutions

Expert Solution

Code:

input_list=[] #declare input list

def get_number(): #get_number() function which takes input and append to list

val=int(input("\nEnter an element: "))
  
input_list.append(val)
  
main() #calling main() after taking input

def display_sum(): #function to display sum

if len(input_list)>0: #if input contains elements then display sum
  
print("\nCurrent sum is {}".format(sum(input_list)))

else:
  
print("\nNo numbers in list.")

main() #calling main() for displaying menu

def display_avg(): #function display average

if len(input_list)>0:
  
print("\nCurrent average is {}".format(sum(input_list)/len(input_list))) #printing average by finding sum / length of list

else:
  
print("\nNo numbers in list.")

main()

def display_max(): #function to display max

if len(input_list)>0:
  
print("\nCurrent highest number is {}".format(max(input_list)))

else:
  
print("\nNo numbers in list.")

main()
  
  
def display_min(): #function to display minimum of input list

if len(input_list)>0:
  
print("\nCurrent lowest number is {}".format(min(input_list))) #printing min value

else:
  
print("\nNo numbers in list.")

main() #calling main() function
  
def display_all(): #display all values in list function

if len(input_list)>0:
  
print("\nAll numbers are {}".format(input_list)) #if list contains elements display values

else:
  
print("\nNo numbers in list.")

main()
  
def quit_program(): #function to quit the program
  
return
  
def main():

print("\nG] Get a number\nS] Display current sum\nA] Display current average")
print("H] Display the current highest number\nL] Display the current lowest number")
print("D] Display all numbers entered\nQ] Quit") #print menu
  
option=input("Enter an option: ") #take option from user
  
if option=='G': #based on option call the appropriate function
  
get_number()

elif option=='S':
  
display_sum()

elif option=='A':
  
display_avg()

elif option=='H':
  
display_max()

elif option=='L':
  
display_min()
  
elif option=='D':
  
display_all()

elif option=='Q':
  
quit_program()

else:
  
print("Invalid option. Select valid option") #any option out of menu print invalid option
  
main()
  
main()

Code and Output Screenshots:

Output:

Note: In python indentation is very important so please refer the attached code screenshots for better and perfect indendation.

Note: if you have any queries please post a comment before giving any reviews thanks a lot..always available to help you...


Related Solutions

Number Analysis Program (Specific Design Specifications) Design a Python program that asks the user to enter...
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,...
PYTHON In this lab we will design a menu-based program. The program will allow users to...
PYTHON In this lab we will design a menu-based program. The program will allow users to decide if they want to convert a binary number to base 10 (decimal) or convert a decimal number to base 2 (binary). It should have four functions menu(), reverse(), base2(), and base10(). Each will be outlined in detail below. A rubric will be included at the bottom of this document. Menu() The goal of menu() is to be the function that orchestrates the flow...
Please write in python Use modular design to write a program that asks the user to...
Please write in python Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. PLANET CONVERSION FACTOR Mercury 0.4155 Venus 0.8975 Earth 1.0000 Moon 0.1660 Mars 0.3507 Jupiter 2.5374 Saturn 1.0677 Uranus 0.8947 Neptune 1.1794 Pluto 0.0899 The...
java code Write a program that gives the user a menu of six choices (use integers)...
java code Write a program that gives the user a menu of six choices (use integers) to select from. The choices are circle, triangle, cone, cylinder, sphere, and quit. (The formulas are given below.) Once the figure is calculated, an informative message should be printed and the user shown the menu again, so that another choice can be made. The formulas are: Area of circle: a = 3.14 * radius * radius Area of triangle: a = ½ base *...
Write a python program to display a menu with the following options: (1) add, (2) subtract,...
Write a python program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. I f the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.
Confused about going through this C program. Thank you Program Specifications: *********************************************** ** MAIN MENU **...
Confused about going through this C program. Thank you Program Specifications: *********************************************** ** MAIN MENU ** *********************************************** A) Enter game results B) Current Record (# of wins and # of losses and # of ties) C) Display ALL results from all games WON D) Display ALL results ordered by opponent score from low to high. E) Quit Your program will have a menu similar to the example above. The game results will simply be the score by your team and...
Please write in Python code Write a program that stores the following data in a tuple:...
Please write in Python code Write a program that stores the following data in a tuple: 54,76,32,14,29,12,64,97,50,86,43,12 The program needs to display a menu to the user, with the following 4 options: 1 – Display minimum 2 – Display maximum 3 – Display total 4 – Display average 5 – Quit Make your program loop back to this menu until the user chooses option 5. Write code for all 4 other menu choices
Write a python program per the following specifications: 1. Populate an array(list) of size n =...
Write a python program per the following specifications: 1. Populate an array(list) of size n = 50 randomly with only integers 0 and 1 2. Repeat step 1 nn = 1000 times using either a while loop or a for loop see below At this point you should have a total of 50000 observations with either 0 or 1 This is our experimental data which we will compare to the theoretical expected result From Lab06template.py import random temp = -1...
in python Using this baseline template, write a program to input a choice from a menu...
in python Using this baseline template, write a program to input a choice from a menu def calcArea(length, width):    pass    def CalcVolumeSa(length, width, height):    pass def menu():    pass        def getValuesArea(): pass    def getValuesVolSa(): pass       def main():    menu() if __name__ == "__main__":    main() [1] - Calculate Area of rectangle [2] - calculate Volume and Surface area of Rectangle [x} - Exit Please select Option: input the appropriate values and calculate...
(+30) Write a python program per the following specifications: Populate an array(list) of size 50 randomly...
(+30) Write a python program per the following specifications: Populate an array(list) of size 50 randomly with only integers 0 and 1 Repeat step1 n = 1000 times using either a while loop or a for loop At this point you should have a total of 50000 observations Display the number of 0’s (use the count() function from prior labs) Display the number of 1’s (use the count() function from prior labs) Using the Binomial distribution formulas Display the expected...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT