用Python写多级菜单小程序
1.程序能够经过用户输入进入下层菜单
2.用户可以输入特定字符返回上级菜单或者退出程序
3.熟练掌握"字典"的使用,
4.嵌套循环,仔细理清逻辑
# -*- coding:utf-8 -*- address ={ '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'google':{} }, '中关村':{ '爱奇艺':{}, '汽车之家':{}, 'youku':{}, }, '上地':{ '百度':{}, }, }, '昌平':{ '沙河':{ '老男孩':{}, '北航':{}, }, '天通苑':{}, '回龙观':{}, }, '朝阳':{}, '东城':{}, }, '上海':{ '闵行':{ "人民广场":{ '炸鸡店':{} } }, '闸北':{ '火车战':{ '携程':{} } }, '浦东':{}, }, '山东':{}, } get_info = False while not get_info: for i in address: print(i) choice = input('请输入城市1:》》》') if choice in address:#不是'='是判断是否在字典中 while not get_info: for i2 in address[choice]: print('\t',i2) choice2 = input('请输入城市2:》》》') if choice2 in address[choice]: while not get_info: for i3 in address[choice][choice2]: print('\t\t',i3) choice3 = input('请输入城市3:》》》') if choice3 in address[choice][choice2]: for i4 in address[choice][choice2][choice3]: print('\t\t\t',i4) choice4 = input('最后一层,按p返回!') if choice4 == 'p': pass if choice4 == 'b': get_info = True if choice3 == 'p': break if choice3 == 'b': get_info = True if choice2 == 'p': break if choice2 == 'b': get_info = True