【问题标题】:Menus and submenus in PythonPython 中的菜单和子菜单
【发布时间】:2023-01-23 00:23:11
【问题描述】:

我是学习 Python 的完全初学者。目前正在进行一项作业,在创建带有子菜单的菜单时遇到问题。我正在尝试正确连接功能并使我的程序正常工作。

我怎样才能让我的子菜单工作?输出不显示子菜单选项。

type def display_header():
    main = "Main Menu"
    txt = main.center(90, ' ')
    print('{:s}'.format('\u0332'.join(txt)))
    print("Please choose an option from the following menu:")
    print("I. Invitee's Information")
    print("F. Food Menu")
    print("D. Drinks Menu")
    print("P. Party Items Menu")
    print("Q. Exit")
    

def get_user_choice():
    
    choice = input("Enter your choice: ")
    return choice


def invitees_menu():


       invitees_menu()
    
    while True:
        choice = invitees_menu()
            
        if choice == "a":
             enter_invitee()
        if choice == "e":
               edit_invitee()
        if choice == "v":
             drinks_menu()    
        if choice == "b":
           display_header()


    print("Invitees' Information Menu")
    print("Please choose an option from the following menu:")
    print("A. Add new invitee information")
    print("E. Edit existing invitee information")
    print("V. View all invitees")
    print("B. Go back to main menu")
    choice = input("Enter your sub-menu choice: ")[0].lower
    return choice


if __name__ == "__main__":
    
    display_header()

    while True:
        choice = get_user_choice()
        
        if choice == "i":
            invitees_menu()
        if choice == "f":
            food_menu()
        if choice == "d":
            drinks_menu()
        if choice == "p":
            party_menu()    
        if choice == "q":
            print ("Thank you for using the program!")
            break

【问题讨论】:

    标签: python


    【解决方案1】:

    我建议第一步是在以下部分中使用递归函数调用清理混乱:

    def invitees_menu():
    
    
           invitees_menu()
        
        while True:
            choice = invitees_menu()
    

    【讨论】:

      猜你喜欢
      • 2019-04-08
      • 2016-03-06
      • 1970-01-01
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 2012-12-21
      • 2018-06-07
      • 1970-01-01
      相关资源
      最近更新 更多