建立一个简单的三级菜单查询

# Author:Macheng

laojia_family = {
"大姑家":{
"代江家":["代江", "大嫂", "代然"],
"代欧夕家":["代欧夕", "小朵朵", "大朵朵"]
},
"二姑家":{
"代国强家":["代国强", "代海丽", "代涵"],
"代国秋家":["代国秋"]
},
"老伯家":{
"张静家":["张静"]
}
}

tag2 = True
tag3 = True
print("-----------有如下长辈列表")
while True:
for i in laojia_family:
print(i)
choice1 = input("-------------请输入你要查询的哪个长辈家呢?(‘q’直接退出程序)")
if choice1 in laojia_family:
old_family_choice = choice1
tag2 = True #重置tag2 为真
while tag2:
for j in laojia_family[old_family_choice]:
print(j)
choice2 = input("-----------请输入你要查询的哪个兄弟家呢?(‘u’ 返回上级,‘q’直接退出程序)")
if choice2 in laojia_family[old_family_choice]:
yung_family_choice = choice2
tag3 = True #重置 tag3 为真
while tag3:
for k in laojia_family[old_family_choice][yung_family_choice]:
print(k)
choice3 = input("------------已经到了菜单的最底层,按‘u’返回上一层,按‘q’直接退出程序")
if choice3 == "u":
tag3 = False
elif choice3 == "q":
exit()
else:
print("你的输入不正确,请重新输入!")
elif choice2 == "u":
tag3 = False
tag2 = False
elif choice2 == "q":
exit()
else:
print("你的输入不正确,请重新输入!")
elif choice1 == "q":
exit()
else:
print("你的输入不正确,请重新输入!")

posted on 2017-12-17 18:03  苦僧  阅读(168)  评论(0)    收藏  举报

导航