Home > OS >  Python: How is the docstring code running and is this the correct way to code a menu?
Python: How is the docstring code running and is this the correct way to code a menu?

Time:11-23

Errors for this codeI don't understand how the code under the docstring is running. I am trying to make a main menu. I also keep getting errors under the comments

def main_menu():
    # Function for the interface where the user is presented with a menu and given the options requiring the user's input
    choice = input("""

    MainName
    
    R - Reporting
    I - Intelligence
    M - Monitoring
    A - About
    Q - Quit

    Choose an option: """)

    if choice == "R" or choice == "r":
        reporting()
    elif choice == "I" or choice == "i":
        intelligence()
    elif choice == "M" or choice == "m":
        monitoring()
    elif choice == "A" or choice == "a":
        about()
    elif choice == "Q" or choice == "q":
        quit()
    else:
        print(" ")
        print("Please try again")
        main_menu()

Is this a correct way to making a menu? The program runs with no error messages but I keep getting problems highlighted.

CodePudding user response:

You are using triple quotes in the input function that takes it as a string! and for the menu it is correct but also checkout the case function newly launched in python version 3.11

CodePudding user response:

  • You are using triple quotes in the input function that takes it as a string! and for the menu it is correct but also checkout the case function newly launched in python version 3.11

  • use VsCode maybe your editor dosen't support it

  • And use main_menu() function outside the if else block

  • Related