python-编写程序实现中文级联菜单

编写程序实现中文级联菜单,建议可以使用pypinyin或其它扩展库。

 

代码:

复制代码
address = {

    '河北': {
        '石家庄': {
            '石家庄铁道大学': {
                '信息学院': {},
                '土木学院': {}
            },
            '河北经贸大学': {
                '工商管理学院': {},
                '计算机学院': {}
            },
        },
        '保定': {
            '华北电力大学': {
                '信息学院': {},
                '土木学院': {}
            },
            '河北大学': {
                '工商管理学院': {},
                '计算机学院': {}
            }
        }
    }
}

get_info = False
while not get_info:
    for i in address:
        print(i)
    choice = input('请输入城市1:')
    if choice in address:  # 不是'='是判断是否在字典中
        while not get_info:
            for i2 in address[choice]:
                print('\t', i2)
            break
    choice2 = input('请输入城市2:')
    if choice2 in address[choice]:
        while not get_info:
            for i3 in address[choice][choice2]:
                print('\t\t', i3)
            break
    choice3 = input('请输入城市3:')
    if choice3 in address[choice][choice2]:
        for i4 in address[choice][choice2][choice3]:
            print('\t\t\t', i4)
        break
    choice4 = input('最后一层,按p返回!')
    if choice4 == 'p':
        pass
    if choice4 == 'b':
        get_info = True
    if choice3 == 'p':
        break
    if choice3 == 'b':
        get_info = True
    if choice2 == 'p':
        break
    if choice2 == 'b':
        get_info = True
复制代码

 

 

 

posted @   睡觉不困  阅读(232)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示