码迷,mamicode.com
首页 > 编程语言 > 详细

Python 城市菜单详解(超详解)

时间:2016-01-13 12:40:21      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

 
print("--------城市查询系统---------")
print("--------按数值进行查询--------")
menu={"内蒙古":{"赤峰市":["赤峰1","赤峰2","赤峰3"],"锡盟":["锡盟1","锡盟2","锡盟3"]},
      "上海":{"青浦":["青浦1","青浦2","青浦3"],"黄埔":["黄埔1","黄埔2","黄埔3"]},
      "山东":{"胶州":["胶州1","胶州2","胶州3"],"济南":["济南1","济南2","济南3"]},
      "河南":{"开封":["河南1","河南2","河南3"],"郑州":["郑州","郑州2","郑州3"]}
      }
flag=True
count = 0
while (flag):
    for i,v in enumerate(menu.keys()):
        print("--->",i,v)                                #打印出第一层key value          
    choice_1=input("请输入对应数字,按q退出:--->").strip() #接收键盘输入 .strip()前后空格都没了
    if choice_1==‘q‘:                                      #判断是不是q是就退出  
        flag=False
        break
    if choice_1.isdigit():                                 #确定输入的是数字
        num=int(choice_1)                                  #是输入的为整形数字
        if num<len(menu):                                  #判断输入的数字是否小于字典里键元素个数
            m=list(menu.keys())                            #把字典中的键植入列表中
            key_1=m[num]                                   #取列表里的值m[0],m[1],m[...]
            print(key_1)
            while(flag):                                   #准备进入第二层菜单
                for i1,v1 in enumerate(menu[key_1]):       #打印出第二层菜单
                    print("--->",i1,v1)                    #打印出第二层
                choice_2=input("返回上一层:b 退出:q 请输入对应数字:").strip()#接收信息进入第三层
                if choice_2.isdigit():
                    num_2=int(choice_2)
                    n=list(menu[key_1].keys())          
                    key_2=n[num_2]
                    while(flag):
                        for i2,v2 in enumerate(menu[key_1][key_2]):#打印第二层菜单的信息
                            print("--->",i2,v2)
                        print("查询完毕!!!!")
                        choice=input("返回上一层:b 退出:q-->")
                        if choice==‘b‘:
                            break
                        elif choice==‘q‘:
                            flag=False
                elif  choice_2==‘b‘:
                    break
                elif  choice_2==‘q‘:
                    flag=False
        else:
            print("****请输入规定范围的数字*****")

    else:
        print("****请输入数字****")
        
        

Python 城市菜单详解(超详解)

标签:

原文地址:http://www.cnblogs.com/taoge8788/p/5126591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!