微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决具有多个菜单的主要功能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 举报,一经查实,本站将立刻删除。