用python写菜单_用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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值