Given the menu with the following options as mentioned above, the call to print_main_menu(main_menu) will output: ======= ====== What would you like to do? L - List A - Add U - Update D Delete S Save the data R Restore data from file Q- Quit this program ========================== Program flow The expected program flow is: The main program starts with a menu of options given above Loop indefinitely (while the user didn't choose to exit): o Print the menu to the user o Get the user's choice from input() o Check if the user's choice is a valid option in the menu (is it one of the dictionary keys?). ■ If the input is a valid option, print the option that user selected ■ If not, simply continue from the top of the loop o If the user entered 'Q', break the while loop Instructions 1. Fix TODO 1: Add the options from the instructions to the menu dictionary inside the main program. 2. Fix TODO 2: Implement the "Quit" option, breaking from the while loop if the user input is an uppercase OR lowercase "Q". 3. 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: print (f"You selected option (opt) to > {the_menu [opt]}.") Hints • Make sure you do not hard-code the menu options in your functions - the options need to be retrieved from the dictionary provided as

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

 

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")

• use a dictionary to store menu items
• use a function to print formatted menu options
• use a while loop to create an interactive program
• check the user input using if branches
• check that an option is correct (verify that a dictionary key exists)
• use break to interrupt the program execution
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:
L : List
A : Add
U : Update
D
Delete
S: Save
R Restore
Q: Quit
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:
Transcribed Image Text:• use a dictionary to store menu items • use a function to print formatted menu options • use a while loop to create an interactive program • check the user input using if branches • check that an option is correct (verify that a dictionary key exists) • use break to interrupt the program execution 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: L : List A : Add U : Update D Delete S: Save R Restore Q: Quit 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:
Given the menu with the following options as mentioned above, the call to print_main_menu(main_menu) will output:
====
====
What would you like to do?
List
A - Add
U - Update
D
Delete
S Save the data
R Restore data from file
Q- Quit this program
=====
Program flow
==============
The expected program flow is:
• The main program starts with a menu of options given above
• Loop indefinitely (while the user didn't choose to exit):
o Print the menu to the user
o Get the user's choice from input()
o
Check if the user's choice is a valid option in the menu (is it one of the dictionary keys?).
■ If the input is a valid option, print the option that user selected
■ If not, simply continue from the top of the loop
o If the user entered 'Q', break the while loop
Instructions
1. Fix TODO 1: Add the options from the instructions to the menu dictionary inside the main program.
2. Fix TODO 2: Implement the "Quit" option, breaking from the while loop if the user input is an uppercase OR lowercase "Q".
3. 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:
print (f"You selected option {opt} to > {the_menu [opt]}.")
Hints
• Make sure you do not hard-code the menu options in your functions - the options need to be retrieved from the dictionary provided as
a parameter to the function.
Transcribed Image Text:Given the menu with the following options as mentioned above, the call to print_main_menu(main_menu) will output: ==== ==== What would you like to do? List A - Add U - Update D Delete S Save the data R Restore data from file Q- Quit this program ===== Program flow ============== The expected program flow is: • The main program starts with a menu of options given above • Loop indefinitely (while the user didn't choose to exit): o Print the menu to the user o Get the user's choice from input() o Check if the user's choice is a valid option in the menu (is it one of the dictionary keys?). ■ If the input is a valid option, print the option that user selected ■ If not, simply continue from the top of the loop o If the user entered 'Q', break the while loop Instructions 1. Fix TODO 1: Add the options from the instructions to the menu dictionary inside the main program. 2. Fix TODO 2: Implement the "Quit" option, breaking from the while loop if the user input is an uppercase OR lowercase "Q". 3. 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: print (f"You selected option {opt} to > {the_menu [opt]}.") Hints • Make sure you do not hard-code the menu options in your functions - the options need to be retrieved from the dictionary provided as a parameter to the function.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY