标签:com 代码 color choice ima src 循环 strong http
定义 database = {} 打印主菜单 用户输入选择 打印二级菜单 用户输入 打印三级菜单 每层输入q 退出程序 每层输入b返回上一层 (没有实现 )
data_base = { ‘shaanxi‘:{ "xi‘an":{ ‘yantaqu‘:[‘dongyilu‘,‘dianzierlu‘,‘taibailu‘], ‘weiyangqu‘:[‘ziwulu‘,‘dahualu‘], ‘changanqu‘:[‘changanlu‘,‘jinhualu‘] }, ‘xianyang‘:{}, ‘weinan‘:{} }, ‘jiangsu‘:{}, ‘nanjing‘:{} } #循环打印字典,第一层 for i in data_base: print(i) choice_1 = input("enter your choice >").strip() if choice_1 in data_base: for i in data_base[choice_1]: print(‘ >‘,i) choice_2 = input("enter your choice >>").strip() if choice_2 in data_base[choice_1]: for i in data_base[choice_1][choice_2]: print(‘ >>‘,i) choice_3 = input("enter your choice >>>").strip() if choice_3 in data_base[choice_1][choice_2]: print(‘ >>>‘,data_base[choice_1][choice_2][choice_3]) elif choice_3 == ‘q‘: print("-------bye-bye------") exit() else: print("\033[1mEntererror!!!\033[0m") elif choice_2 == ‘q‘: print("---------bye-bye------") exit() else: print("\033[1mEntererror!!!\033[0m") elif choice_1 == ‘q‘: print("------bye-bye--------") exit() else: print("\033[1mEntererror!!!\033[0m")
#打印完整字典 #print(data_base) #print(data_base[choice_1]) #打印第一层 #print(data_base[choice_1][choice_2]) #打印第2层 # print(data_base[choice_1][choice_2][choice_3] #打印第3层
2)循环打印字典
#循环打印字典,第一层 # for i in data_base: # print(i)
字体加粗 print("\033[1mEntererror!!!\033[0m")
标签:com 代码 color choice ima src 循环 strong http
原文地址:http://www.cnblogs.com/venicid/p/7241358.html