with open('三级菜单', 'r', encoding='utf-8') as f_read:
date = f_read.read()
#print(date.replace(' ', '').replace('\n', ''))
#print(type(date))
menu = eval(date)
current_layer = menu
parent_layer = []
while True:
#打印当前层并进入修改逻辑
print(' '.join(list(current_layer.keys())))
operation = input('进入哪一层(城市名称)修改c 删除d 增加a 返回r 退出q:')
if operation == 'c':
choice_of_city = input('哪个城市:')
if choice_of_city in current_layer:
change_of_city = input('修改成:')
#C++思想,变量存于变量
# s = str(current_layer)
# s = s.replace(choice_of_city, change_of_city)
# current_layer = eval(s)
#py思想,变量存档数据地址,操作变量相当于操作内存
del current_layer[choice_of_city]
current_layer[change_of_city]
Python入门(七)——文件操作作业:多级菜单高级版,可以修改字典
最新推荐文章于 2023-12-05 15:46:52 发布