python第一天作业:字典

 

作业三:多级菜单
  • 三级菜单
  • 可依次选择进入各子菜单
  • 所需新知识点:列表、字典

break_flag = False
count = 0
while not break_flag:
print("111111层")
while not break_flag:
print("222222222层")
while not break_flag:
print("3333333层")
count += 1
if count > 10:
break_flag =True


print("keep")


menu = {
'浙江':{
'杭州':{
'西湖':{
'西溪',
'三墩'},
'滨江':{'滨和', '高新'}
},
'丽水':{
'龙泉':{'宝剑', '瓷器'},
'青田':{'石雕', '华侨'},
'缙云':{'烧饼', '木雕'},
},
},
'山东':{
'烟台':{'大海', '日照'},
'青岛':{'平度', '黄岛'},
'东营':{'利津', '垦利'}
},
'广东':{
'深圳':{'南山', '福田'},
'梅州':{'五华', '兴宁'},
'佛山':{'三水', '桂城'}
}
}

ext_flage= False
while not ext_flage:
for lev1 in menu:
print(lev1)
choice = input("lev1>>:").strip()
if len(choice) == 0: continue
if choice == "b":break
if choice == "q":
ext_flage = True
if choice in menu[choice]:
while not ext_flage:
for lev2 in menu[choice]:
print(lev2)
choice2 = input("lev2>>:").strip()
if len(choice2) == 0 :continue
if choice2 == "b":break
if choice2 == "q":
ext_flage = True
if choice2 in menu[choice][choice2]:
while not ext_flage:
for lev3 in menu[choice][choice2]:
print(lev3)
choice3 = input("lev3>>:").strip()
if len(choice3)== 0: continue
if choice3 =="b":break
if choice3 =="q":
ext_flage = True
if choice3 in menu[choice][choice2][choice3]:
while not ext_flage:
for lev4 in [choice][choice2][choice3]:
print(lev4)
choice4 = input("lev4>>:").strip()
if len(choice4) == 0 : continue
if choice3 == "b" :break
if choice3 == "q" :
ext_flage = True
                    continue

posted @ 2017-08-01 20:26  天涯客2017  阅读(168)  评论(0编辑  收藏  举报