欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python字典實(shí)現(xiàn)簡(jiǎn)單的三級(jí)菜單(實(shí)例講解)

 更新時(shí)間:2017年07月31日 08:20:31   投稿:jingxian  
下面小編就為大家?guī)硪黄狿ython字典實(shí)現(xiàn)簡(jiǎn)單的三級(jí)菜單(實(shí)例講解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

如下所示:

data = {
 "北京":{
  "昌平":{"沙河":["oldboy","test"],"天通苑":["鏈接地產(chǎn)","我愛我家"]},
  "朝陽(yáng)":{"望京":["奔馳","陌陌"],"國(guó)貿(mào)":["CICC","HP"],"東直門":["advent","飛信"]},
  "海淀":{}
 },
 "山東":{
  "德州":{},
  "青島":{},
  "濟(jì)南":{}
 },
 "廣東":{
  "東莞":{},
  "常熟":{},
  "佛山":{}
 }
}
exit_flag = False
while not exit_flag:
 for i in data:
  print(i)
 choice_s = input("請(qǐng)輸入以上任一省或直轄市名稱>>>:")
 if choice_s in data:
  while not exit_flag:
   for i in data[choice_s]:
    print("\t",i)
   choice_q = input("請(qǐng)輸入以上任一市區(qū)名稱>>>:")
   if choice_q in data[choice_s]:
    while not exit_flag:
     for i in data[choice_s][choice_q]:
      print("\t\t",i)
     choice_j = input("請(qǐng)輸入以上任一街道名稱>>>:")
     if choice_j in data[choice_s][choice_q]:
      for i in data[choice_s][choice_q][choice_j]:
       print("\t\t",i)
      last = input("最后一層,按b返回>>>:")
      if last == "b":
       pass
      elif last == "q":
       exit_flag = True
     if choice_j == "b":
      break
     elif choice_j == "q":
      exit_flag = True
   if choice_q == "b":
    break
   elif choice_q == "q":
    exit_flag = True

要點(diǎn):

1、字典的層級(jí)關(guān)系

2、break是終止本次循環(huán),pass是什么也不做,一個(gè)占位符而已

3、巧妙使用exit_flag = False

以上這篇Python字典實(shí)現(xiàn)簡(jiǎn)單的三級(jí)菜單(實(shí)例講解)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論