Please use Python Introduction In this lab, we will be building an application that uses an interactive menu. Let's say
Posted: Fri May 20, 2022 6:29 pm
Please use Python
Introduction
In this lab, we will be building an application that uses an
interactive menu.
Let's say our high-level menu has the following options:
These key-option mappings will be stored in a dictionary in the
main program.
print_main_menu() function
Write the print_main_menu() that accepts a dictionary
of keys-options like the one shown above and prints the menu
options stored in that dictionary in an easy-to-read format. Below
is an example of the result of
calling print_main_menu() (notice the question it asks at
the top - it is part of the function output):
Example
Given the menu with the following options as mentioned above,
the call to print_main_menu(main_menu) will output:
Program flow
The expected program flow is:
Instructions
Fix TODO 1: Add the options from the instructions
to the_menu dictionary inside the main program.
Fix TODO 2: Implement the "Quit" option, breaking from the while
loop if the user input is an uppercase OR lowercase "Q".
Fix TODO 3: Check whether a provided option is a valid menu
option.
Each time a valid menu option is
provided, the program "echoes" it back to the user as follows:
Hints
FINISH BELOW:
def print_main_menu(menu):
"""
Given a dictionary with the menu,
prints the keys and values as the
formatted options.
Adds additional prints for decoration
and outputs a question
"What would you like to do?"
"""
if __name__ == "__main__":
the_menu = {} # TODO 1: add the options from the
instructions
opt = None
while True:
# print_main_menu(...) # TODO 1:
uncomment, define the function, and call with the menu as an
argument
print("::: Enter an option")
opt = input("> ")
if opt == ...: # TODO 2: make Q or q
quit the program
print("Goodbye!\n")
break # exit the main
`while` loop
else:
if ...: # TODO 3: check
of the character stored in opt is in the_menu dictionary
print(f"You
selected option {opt} to > {the_menu[opt]}.")
else:
print(f"WARNING: {opt} is an invalid option.\n")
Introduction
In this lab, we will be building an application that uses an
interactive menu.
Let's say our high-level menu has the following options:
These key-option mappings will be stored in a dictionary in the
main program.
print_main_menu() function
Write the print_main_menu() that accepts a dictionary
of keys-options like the one shown above and prints the menu
options stored in that dictionary in an easy-to-read format. Below
is an example of the result of
calling print_main_menu() (notice the question it asks at
the top - it is part of the function output):
Example
Given the menu with the following options as mentioned above,
the call to print_main_menu(main_menu) will output:
Program flow
The expected program flow is:
Instructions
Fix TODO 1: Add the options from the instructions
to the_menu dictionary inside the main program.
Fix TODO 2: Implement the "Quit" option, breaking from the while
loop if the user input is an uppercase OR lowercase "Q".
Fix TODO 3: Check whether a provided option is a valid menu
option.
Each time a valid menu option is
provided, the program "echoes" it back to the user as follows:
Hints
FINISH BELOW:
def print_main_menu(menu):
"""
Given a dictionary with the menu,
prints the keys and values as the
formatted options.
Adds additional prints for decoration
and outputs a question
"What would you like to do?"
"""
if __name__ == "__main__":
the_menu = {} # TODO 1: add the options from the
instructions
opt = None
while True:
# print_main_menu(...) # TODO 1:
uncomment, define the function, and call with the menu as an
argument
print("::: Enter an option")
opt = input("> ")
if opt == ...: # TODO 2: make Q or q
quit the program
print("Goodbye!\n")
break # exit the main
`while` loop
else:
if ...: # TODO 3: check
of the character stored in opt is in the_menu dictionary
print(f"You
selected option {opt} to > {the_menu[opt]}.")
else:
print(f"WARNING: {opt} is an invalid option.\n")