码迷,mamicode.com
首页 > 编程语言 > 详细

Python <---> 小课题练习作业

时间:2017-06-01 11:18:28      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:选项   strong   利用   layer   strip   pytho   ble   嵌套   选择   

作业一

       输出目录,可以选择目录进入,可以回退、推出!

#conding:utf8


menu = {‘北京‘:{‘昌平‘:{‘沙河‘:{‘昌平妇幼‘,}},‘海淀‘:{‘海淀一区‘:{‘海淀二区‘},}},} #字典嵌套

current_layer = menu #利用此变量来记录当前的层的位置
pre_menu = [] #用【】来记录每一层

while True:
for k in current_layer:
print (k)
choice = input(‘>>>>>>>:‘).strip() #去除输入选项连边的空格
if len(choice) == 0: #通过len的长度来判断用户是否输入了
continue

if choice in current_layer:
pre_menu.append(current_layer)
current_layer = current_layer[choice]
elif choice == ‘b‘:
if len(pre_menu) > 0: #通过大于0 来判断,还有目录可退
current_layer = pre_menu.pop() #利用pop来弹出上面的一层。
elif choice == ‘q‘:
exit()

Python <---> 小课题练习作业

标签:选项   strong   利用   layer   strip   pytho   ble   嵌套   选择   

原文地址:http://www.cnblogs.com/nopnog/p/6927870.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!