【Python】Third day of homework

程序练习:

1、打印省,市,县三级菜单

2、可返回上一级

3、可随时推出程序

 

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
dictionary={
    "江苏省":{
        "南京市":{"江宁区":{},"市区":{}},
        "苏州市":{"虎丘区":{},"姑苏区":{}},
        "无锡市":{"高新区":{},"市区":{}}
    },
    "浙江省":{
        "舟山市":{"定海区":{},"普陀区":{}},
        "杭州市":{"上城区":{},"西湖区":{}},
        "宁波市":{"北仑区":{},"江北区":{}}
    }
}
flag=False
while not flag:
    for i in dictionary:
        print(i)
    choice1=input("请输入》》》:")
    if choice1 in dictionary:
            while not flag:
                for i1 in dictionary[choice1]:
                    print("\t",i1)
                choice2=input("请输入》》》:")
                if choice2 in dictionary[choice1]:
                        while not flag:
                            for i2 in dictionary[choice1][choice2]:
                                print("\t\t",i2)
                            choice3=input("请输入》》》:")
                            if choice3 in dictionary[choice1][choice2]:
                                    for i3 in dictionary[choice1][choice2][choice3]:
                                        print("\t\t\t",i3)
                                    choice4=input("已经到底了,请按“b”返回上一层,按“q”退出!:")
                                    if choice4=='b':
                                        pass
                                    elif choice4=='q':
                                        flag=True
                            if choice3 == 'b':
                                break
                            elif choice3 == 'q':
                                flag = True
                if choice2 == 'b':
                    break
                elif choice2 == 'q':
                    flag = True
    if choice1 == 'b':
        flag=True
    elif choice1 == 'q':
        flag = True

About the Author

发表评论

电子邮件地址不会被公开。