三級菜單實例

import json

xxl = {'北京': {'天安': {"東京": ["屍體", "大多數已經腐爛!"], "偉人": ["紅旗", "升旗儀式!"]},
'長城': {"地獄": ["惡魔", "種類多,各種奇葩都有!"], "天使": ["墜落", "翅膀毛掉光了!"]},
'堵車': {'堵車': ["車多", "還不如兩條腿走!"], '加塞': ["擁擠", "撈出車禍!"]}},
'江蘇': {'無錫': {'薈聚': ["吃喝", "購物休閒好地方!"]}, '常州': {'恐龍': ["侏羅紀", "體驗恐龍時代"]}, '蘇州': {'sbs': ["電視", "電視塔新建在南施街地鐵口附近"]}},
'廣東': {}, }

while True:
for i in xxl:
print(i)
choise = input("按d退出程序或者選擇進入1》:")
if choise in xxl:
while True:
for i2 in xxl[choise]:# 打印每層的key
print("\t", i2)
choise2 = input("選擇進入2》:")
if choise2 in xxl[choise]:
while True:
for i3 in xxl[choise][choise2]:
print("\t\t", i3)
choise3 = input("選擇進入3》:")
if choise3 in xxl[choise][choise2]:
for i4 in xxl[choise][choise2][choise3]:
print("\t\t", i4)
choise4 = input("最後一層,按b返回》:")
if choise4 == "b":
pass
if choise3 == "b": # 結束當前層的循環
break
if choise2== "b":
break
if choise == "b":
break
if choise == "d":
f = open("dic.json", 'w', encoding="utf-8")
json.dump(xxl, f)
break

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章