python 练习2字典打印三级菜单
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 练习2字典打印三级菜单相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python # -*- coding:utf-8 -*- # @Time : 2017/10/21 0021 16:19 # @Author : ming Northeast = { "吉林省": { "长春市": ["朝阳区", "南关区", "宽城区", "二道区", "双阳去", "绿园区", "德惠", "九台"], "吉林市": ["船营区", "丰满区", "桦甸市", "永吉县", "丰满区", "舒兰市"], "四平市": ["铁西区", "铁东区", "双辽市", "公主岭市", "犁树市", "伊通"] }, "黑龙江省": { "哈尔滨市": ["道里区", "南岗区", "双城区", "呼兰区", "平房区", "松北区"], "齐齐哈尔市": ["龙沙区", "建华区", "龙江县", "富裕县", "依安县"], "鸡西市": ["鸡冠区", "恒山区", "密山市", "城子河区", "梨树区"] }, "辽宁省": { "沈阳市": ["辽中", "康民区", "新民区", "法库区"], "大连市": ["长海", "金州", "庄河", "普兰店", "瓦房店"], "鞍山市": ["台安", "海城", "岫岩"] }, } for p in Northeast: print p Province = raw_input("请输入省份:") for c in Northeast[Province]: print c City = raw_input("请输入市:") for a in Northeast[Province][City]: print a #运行结果: # 黑龙江省 # 辽宁省 # 吉林省 # 请输入省份:辽宁省 # 沈阳市 # 大连市 # 鞍山市 # 请输入市:沈阳市 # 辽中 # 康民区 # 新民区 # 法库区
本文出自 “学无止境” 博客,请务必保留此出处http://20120809.blog.51cto.com/10893237/1975665
以上是关于python 练习2字典打印三级菜单的主要内容,如果未能解决你的问题,请参考以下文章