具有多个菜单的主要功能python

问题描述

在下面的代码中,我想显示一个带有初始菜单的主功能,但一旦对初始菜单做出决定,我也想要一些子菜单。让我详细说明一下:

在我的第一个菜单(初始菜单)中,我提供了在生日、事件或退出之间进行选择的选项...一旦选择了一个选项,我将继续选择特定的选项,具体取决于我选择的选项想要创建一个带有该特定选项选项的子菜单。所有菜单都将能够处理用户指定的输入并相应地继续。

这是一些代码

def main():
    choice = ''
    while choice != 'q':
        choice = input('\nWelcome to your own personalized calendar select from the options below in order to begin:\n\t
Enter the number \'1\' if you wish to access the birthday directory.\n
Enter the number \'2\' if you wish to access the event directory.\n
Enter the letter \'Q\' if you wish to terminate the program.
\n\nEnter Your Selection: ').lower().lstrip().rstrip()
        
        if choice == 'q':
            print('Program Terminated')
            break
        
        
        elif choice == '1':
            choices = ''
            while choices != 'q':
                
                choices = input('\t\n\nWelcome to the birthday directory please read the options below and type in your selection\n\t
Type \'add\' if you wish to add a birthday to the directory.\n
Type \'search month\' if you wish to search for a birthday by month.\n
Type \'search name\' if you wish to search for a birthday by name.\n
Type \'delete\' if you wish to delete a birthday entry from the directory.\n
Enter the letter \'Q\' if you wish to terminate this program.\n\n
Enter Your Selection: ').lower().lstrip().rstrip()
                
                if choices == 'q':
                    break 
                elif choices == 'add':
                    pass
                elif choices == 'search month':
                    pass
                elif choices == 'search name':
                    pass
                elif choices == 'delete':
                    pass
                
        elif choice == '2':
            choose = ''
            while choose != 'q':
                choose = input('\t\n\nWelcome to the events directory please read the options below and type in your selection\n\t
Type \'add\' if you wish to add an event to the directory.\n
Type \'search month\' if you wish to search for an event by month.\n
Type \'search name\' if you wish to search for an event by name.\n
Type \'delete\' if you wish to delete an event from the directory.\n
Enter the letter \'Q\' if you wish to terminate this program.\n\n
Enter Your Selection: ').lower().lstrip().rstrip()
                
                if choose == 'q':
                    break
                elif choose == 'add':
                    pass
                elif choose == 'search month':
                    pass
                elif choose == 'search name':
                    pass
                elif choose == 'delete':
                    pass                
    

代码将允许用户输入输入并在多个菜单中进行相应操作。如果用户选择退出菜单,它将返回到主菜单,然后您可以从那里退出...如果您想完全从子菜单退出/终止,您只需设置 choice = ' q' 在您退出的 if 语句之后的第二个 while 循环中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)