python三级菜单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python三级菜单相关的知识,希望对你有一定的参考价值。

主要练习嵌套循环和标志位的使用方法:


#!/usr/local/python/bin/python3.6

#-*-coding:utf-8-*-

data = {

  "中国":{"河北":["石家庄","廊坊","保定"],"四川":["成都","重庆","南充"],"湖北":["武汉","黄石","襄阳"]},

  "美国":{"华盛顿":["芝加哥","旧金山","亚特兰大"],"纽约":["布朗克斯","国王","曼哈顿"],"德克萨斯":["休斯顿","达拉斯","圣安东尼奥"]}

}


flag = False

while not flag:

  for i in data:

    print(i)

  choice = input("请选择:")

  if choice in data:

    while not flag:

      for j in data[choice]:

        print(j)

      choice2 = input("请选择:")

      if choice2 in data[choice]:

        while not flag:

          for k in data[choice][choice2] :

            print(k)

          choice3 = input("最后一层,【e】返回上一级,【q】退出:")

          if choice3 == "e":

            break

          elif choice3 == "q":

            flag = True

      if choice2 == "e":

        break

      elif choice2 == "q":

        flag = True

  if choice == "q":

    flag = True


以上是关于python三级菜单的主要内容,如果未能解决你的问题,请参考以下文章

Python进阶实战之三级菜单

Python 三级菜单

python- 简单练习:python三级菜单优化

python三级菜单

Python中三级菜单 选择进入各级菜单

Python进阶实战之三级菜单