python学习---三级菜单

开发环境:

  OS:64位Windows 7
  IDE:pycharm4.0.4
  python版本:2.7.10

程序简述:

  a、本程序实现的功能为球迷可以选出自己喜欢的球队与球员
  b、程序共三级目录,第一级分东部与西部分区,第二级为各分区下的球队列表,第三级为球队列表下的球员列表,每个球员的基本信息为球员比赛角色
  c、在每一级目录下,客户可以在当级目录下进行选择,序号对应选项,q对应退出整个程序,b代表回到上一级重新选择。

版权说明:

  本多级菜单程序只做python学习使用,版权有作者所有,未经过作者本人同意,不得将此多级菜单程序应用于商业用途。


#
-*- coding:utf-8 -*- __author__ = 'bruce' levelist = { 'EastDist': { "Cavs":{ "LBJ":['F'], "Love":["C"], "Iving":["S"] }, "Bulls":{ "Rose":["S"], "Gassol":["C"], "Butter":['F'] }, "Heat":{ "Wade":["S"], "Bosh":["F"], "Deng":["S"] }, }, "WestDist": { "Warriors":{ "Curry":["S"], "Thompson":["S"], "Green":['F'] }, "Spurs":{ "Duncan":['F'], "Park":["S"], "Ginobili":["S"] }, "Thunders":{ "Durant":['F'], "Wesbrook":["S"], "Yibaka":["C"] }, }, } flag = True while flag: print '----------------------分区选择-------------------------------------' for i in range(len(levelist.keys())): print i,levelist.keys()[i] print '------------------------------------------------------------------' dictselect = raw_input("选择球队分区(按q退出):").strip() print "-------------------------球队选择----------------------------------" # if dictselect.isdigit():#无法判断选项以外的其他数字,报错 if dictselect == "0" or dictselect == "1": dictselect = int(dictselect) # print levelist.keys()[dictselect] #取出分区名字,同时是球队字典的键值 dictkey = levelist.keys()[dictselect] #取出分区名字,同时是球队字典的键值 while flag: for j in range(len(levelist[dictkey])): print j,levelist[dictkey].keys()[j] # print '------------------------------------------------------------------' # print levelist[teamkey].keys()[1] teamselect = raw_input("选择球队序号(按q退出,按b返回上一级):").strip() print "-------------------------球员选择----------------------------------" if teamselect.isdigit(): teamselect = int(teamselect) teamkey = levelist[dictkey].keys()[teamselect]#取出球队名字,同时也是球员字典的键值 # print teamkey #取出球队名字,同时也是球员字典的键值 # print levelist[dictkey][teamkey] #取出[分区][球队]以下的球员字典 while flag: for l in range(len(levelist[dictkey][teamkey])): print l,levelist[dictkey][teamkey].keys()[l] print '---------------------------------------------------------------' playerselect = raw_input("选择球员序号(按q退出,按b返回上一级):").strip() if playerselect.isdigit(): print "到底了,请选择q退出,或按b返回上一级" elif playerselect =="b": break elif playerselect =="q": flag = False # break else: print "您的输入有误,请重新输入" elif teamselect == "b": break elif teamselect == "q": flag = False else: print "您的输入有误,请重新输入" elif dictselect == "q": flag = False else: print "您的输入有误,请重新输入"

 

你可能感兴趣的:(python学习---三级菜单)