牛刀小试-三级菜单
1,打印省、市、县区三级菜单;
2,可随意切换上下级;
3,可随时退出程序
#author:张浩 #date:2019/8/15 dict_country = { '浙江省':{'杭州市':{'西湖区':{'西湖'},'拱墅区':{'万达'},'余杭区':{'阿里'}}}, '江苏省':{'南京市':{'江宁区':{'美食'},'兴合区':{'美女'}}}, '上海':{'宝山区':{'大山'},'嘉定区':{'小河'}} } flag = True while flag: for province in dict_country: print(province) choose1 = input("请输入选择对象(q退出):") if choose1 in dict_country: while flag: a = dict_country[choose1] for city in a: print(city) choose2 = input("请输入选择对象(up返回上一层,q退出):") if choose2 in a : while flag: b = a[choose2] for city_3 in b: print(city_3) choose3 = input("请输入选择对象(up返回上一层,q退出):") if choose3 in b : if type(b).__name__ != 'set': while flag: c = b[choose3] for d in c: print(d) choose4 = input("已最底层,是否返回上层(up返回上一层,q退出):") if choose4 == 'up': break elif choose4 == 'q': flag = False # break else: print("4,输入错误,请重新输入!") continue else: print("已最底层,返回上一层请输入up!") continue if choose3 == 'up': break elif choose3 == 'q': flag = False # break else: print("3,输入有误,请重新输入!") elif choose2 == 'up': break elif choose2 == 'q': flag = False # break else : print("2,输入有误,请重新输入!") elif choose1 == 'q': flag = False else: print("1,输入有误,请重新输入!")