#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "Deakin"
# Email: 469792427@qq.com
# Date: 2018/1/14
#1. 运行程序输出第一级菜单
#2. 选择一级菜单某项,输出二级菜单,同理输出三级菜单
#3. 菜单数据保存在文件中
#4. 让用户选择是否要退出
#5. 有返回上一级菜单的功能
f=open('city','r',encoding='utf-8')
dic=f.read()
#print(dic)
#print(type(dic))
#print(type(eval(dic)))
quit=True
while quit:
for i in eval(dic): #将文件中的字典直接使用,转换格式
print(i)
choice=input("选择城市,按'r'返回上一层,按'q'退出:")
if choice in eval(dic):
while quit:
for i2 in eval(dic)[choice]:
print('\t',i2)
choice2=input("选择城区,按'r'返回上一层,按'q'退出")
if choice2 in eval(dic)[choice]:
while quit:
for i3 in eval(dic)[choice][choice2]:
print('\t\t',i3)
choice3=input("选择街道,按'r'返回上一层,按'q退出")
if choice3 in eval(dic)[choice][choice2]:
for i4 in eval(dic)[choice][choice2][choice3]:
print('\t\t\t',i4)
choice4 = input("下属公司,按'r'返回上一层,按'q退出")
if choice4=='r':
pass
elif choice=='q':
quit=False
else:
print("最后一层,按'r'返回上一层,按'q退出")
if choice3=='r':
break
elif choice3=='q':
quit=False
else:
print("请输入列表中的街道名称")
elif choice2=="r":
break
elif choice2 == "q":
quit = False
else:
print("请输入列表中的城区名称")
elif choice == "q":
quit = False
else:
print("请输入列表中的城市名称")
转载于:https://www.cnblogs.com/Deakin-Du/p/8284947.html