This is really a concept question from a beginning programmer. I am still working on this program. When I type in a menu option not only does the corresponding if statement print but, the else statement does at well. With this python knowledge I have I do not understand why. I would like to know what is triggering my else statement.
FIND_LOWEST_NUMBER_CHOICE = 1
FIND_HIGHEST_NUMBER_CHOICE = 2
FIND_TOTAL_CHOICE = 3
FIND_AVERAGE_CHOICE = 4
QUIT_CHOICE = 5
def main():
numbers = get_values()
get_analysis(numbers)
def get_values():
print('Please enter 20 numbers')
values =[]
for i in range(20):
value =(int(input("Enter A Random Number " + str(i + 1) + ": ")))
values.append(value)
return values
def get_analysis (numbers):
choice = 0
while choice != QUIT_CHOICE:
display_menu()
choice = int(input('Enter your choice:'))
if choice == FIND_LOWEST_NUMBER_CHOICE:
print("The Lowest Number Is:", min(numbers))
if choice == FIND_HIGHEST_NUMBER_CHOICE:
print("The Highest Number Is:", max(numbers))
if choice == FIND_TOTAL_CHOICE:
print("The Sum The Numbers Is:", sum(numbers))
if choice == FIND_AVERAGE_CHOICE:
print("The Average The Numbers Is:", sum(numbers)/len(numbers))
if choice == QUIT_CHOICE:
print("Exiting program....")
else:
print('Error')
def display_menu():
print(' Menu')
print('1. Show lowest number')
print('2. Show highest number')
print('3. Show total of numbers')
print('4. Show average of numbers')
print('5. Quit')
main()
Thank you!!
Aucun commentaire:
Enregistrer un commentaire