Day1作业-三级菜单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Day1作业-三级菜单相关的知识,希望对你有一定的参考价值。
# /usr/bin/env python
# -*- coding: utf-8 -*-
# Author:jenvid.yang
import json
filecontent = open(‘../config/menue.json‘)
content = json.load(filecontent)
print(type(content))
filecontent.close()
while True:
for i in content:
print(content.index(i), i[‘name‘] + ‘省‘) # 打印每个省的索引和名字
province_id_input = input("pls input province index(q for exit):")
if province_id_input.isdigit():
province_id=int(province_id_input)
if 0 <= province_id <= len(content):
for i in content[province_id][‘city‘]:
print(content[province_id][‘city‘].index(i), i[‘name‘])
while True:
city_id_input = input("pls input city index(b for back/q for exit):")
if city_id_input.isdigit():
city_id = int(city_id_input)
for i in (content[province_id][‘city‘][city_id][‘area‘]):
print(i)
elif city_id_input == ‘q‘:
exit()
elif city_id_input == ‘b‘:
break
else:
print("illge input,pls input again ")
break
elif province_id_input ==‘q‘:
exit()
else:
print("illge input,pls input again ")
以上是关于Day1作业-三级菜单的主要内容,如果未能解决你的问题,请参考以下文章