Python练习之三级菜单

# -*- coding: utf-8 -*-
data ={
    "北京市":{
        "东城区":{
            "东城A1": ["奇虎", "百度", "网易"],
            "东城A2": ["北京大学", "清华大学"]
        },
        "西城区": {},
        "朝阳区": {}
    },
    "天津市": {
      "和平区": {},
      "滨海新区": {},
      "南开区": {}
      },
    "上海市":{
      "黄浦区": {},
      "徐汇区": {},
      "静安区": {},
      "普陀区": {}
      }
}
count = 0
while True:
    for i in data:
        print(i)
    while True:
        choice1 = raw_input("Please Enter the City:")
        if choice1 in data:
            while True:
                for i2 in data[choice1]:
                    print(i2)
                while True:
                    choice2 = raw_input("plese Enter the quyu:")
                    if choice2 in data[choice1]:
                        while True:
                            for i3 in data[choice1][choice2]:
                                print(i3)
                            while True:
                                choice3 = raw_input("plese Enter the jiedao:")
                                if choice3 in data[choice1][choice2]:
                                    print("%s"%data[choice1][choice2][choice3])
                                    while True:
                                        choice4 = raw_input("plese Enter the b:")
                                        if choice4 == "b":
                                            count += 1
                                            break
                                        else:
                                            print("输入不正确,请重新输入:")
                                    if count <= 1:
                                        count += 1
                                        break
                                    else:
                                        count = 0
                                elif choice3 == "b":
                                    break
                                else:
                                    print("输入不正确,请重新输入:")
                                    continue
                            if count <= 1:
                                count += 1
                                break
                            else:
                                count = 0
                        if count <= 1:
                            count += 1
                            break
                        else:
                            count = 0
                    elif choice2 == "b":
                        break
                    else:
                        print("输入不正确,请重新输入:")
                        continue
                if count <= 1:
                    count += 1
                    break
                else:
                    count = 0
            if count <= 1:
                count += 1
                break
            else:
                count = 0
        elif choice1 == "b":
            print("退出!")
            break
        else:
            print("输入不正确,请重新输入:")
    if count <= 1:
        count += 1
        break
    else:
        count = 0

你可能感兴趣的:(Python)