1.2k views
1 vote
Implement a menu with the following options:

1. Big Mac

2. Quarter Pounder with Cheese

3. Double Cheeseburger

4. Crispy Chicken Sandwich

5. Filet-O-Fish

If the user enters an invalid option, let him/her know of this fact, redisplay the menu, and let them enter an option again.

Once a valid option is received, Display the message: "(meal name) coming up", ane end the program.

For example, if they enter 3, display: "Double Cheeseburger coming up" and exit.

1 Answer

3 votes

Final answer:

To implement a menu with the provided options, you can use a loop to continuously prompt the user for their choice, display the menu options using a numbered list, validate the input, and display the selected meal before ending the program.

Step-by-step explanation:

To implement a menu with the provided options, you can use a loop to continuously prompt the user for their choice. You can display the menu options using a numbered list and ask the user to enter their choice. If the input is not a valid option, you can display an error message and prompt them to enter again. Once a valid option is received, you can display a confirmation message and end the program.

Here's an example code snippet in Python:

options = ['Big Mac', 'Quarter Pounder with Cheese', 'Double Cheeseburger', 'Crispy Chicken Sandwich', 'Filet-O-Fish']

while True:
print('Menu:')
for i, option in enumerate(options, start=1):
print(f'{i}. {option}')
choice = input('Enter your choice: ')
if choice.isnumeric() and 1 <= int(choice) <= len(options):
meal = options[int(choice) - 1]
print(f'{meal} coming up')
break
else:
print('Invalid option. Please try again.')

User Bartosz Bilicki
by
7.6k points