dimanche 14 février 2021

Invalid Input in While-Loop if/elif/else Menu

I have created a menu from which to select an option:

'''

def menu():
    print('Menu:')
    print('[0]: Terminate program')
    print('[1]: Most Impactful Exercises Regardless of Area')
    print('[2]: Most Impactful Exercises Considering Area')
    print('[3]: Exercise Information: average impact considering area, distribution of impact level regrdless of area, distribution of impact level considering area')
    print('[4]: Average Score Considering Both Exercise and Area')
    print('[5]: Least Impactful Exercises Regardless of Area')
    print('[6]: Least Impactful Exercises Considering Area')

'''

I then print the menu and ask for an input:

'''

menu()

try:

choice = int(input('Carefully input the exact number corresponding to your desired graph:'))

'''

Then an if/elif/else loop starts:

'''

while option != 0:

if choice == 1:
   common_RoA()
   MIERoA()
elif choice == 2:
   common_CA()
   MIECA()
elif choice == 3:
   EI()
elif choice == 4:
   ASCBEA()
elif choice == 5:
   common_RoA()
   LIERoA()
elif choice == 6:
   common_CA()
   LIECA()
else:
   print("Invalid choice")

# Show Menu Again
menu()

# Get Input Again
choice = int(input('Carefully input the exact number corresponding to your desired graph:'))
                        
# When choice == 0

print("Goodbye!")
exit()

'''

Where MIERoA, MIECa, ASCBEA, etc are previously defined functions.

However, when an input is given, the following is printed:

'''

Invalid choice

'''

How do I fix this problem and allow for the defined functions to be executed?

Aucun commentaire:

Enregistrer un commentaire