2.多级菜单
来源:互联网 发布:淘宝内部劵骗局 编辑:程序博客网 时间:2024/06/05 18:57
多级菜单
2.可依次选择进入各子菜单
3.所需新知识点:列表、字典
city_dict = { '山西': {'太原': ['晋祠', '迎泽公园'], '吕梁': ['交口县', '离石'] }, '天津': {'滨海新区': ['天津科技大学', '外滩公园'], '南开区': ['南开大学', '天津大学'] }, '广州': {'天河': ['天河体育馆', '金山大厦'], '越秀': ['越秀公园', '光孝寺'] } }city_index = [(index, key) for index, key in enumerate(city_dict)]city_index.append((len(city_index), '退出'))while True: print('欢迎查询城市信息') print('-----------------') for i in city_index: for j in i: print(j, end=' ') print(' ') get_city = input('请输入查询索引号:') if not get_city.isdigit(): print('请输入一个数字...') continue elif int(get_city) >= len(city_index): print('您输入的数字太大!') continue elif int(get_city) == len(city_index)-1: print('欢迎您下次登陆,再见!') break else: chose_city = city_index[int(get_city)][1] area_index = [(index, key) for index, key in enumerate(city_dict[chose_city])] area_index.append((len(area_index), '返回')) while True: for i in area_index: for j in i: print(j, end='') print('') get_area = input('请输入查询索引号') if not get_area.isdigit(): print('请输入一个数字...') continue elif int(get_area) >= len(area_index): print('您输入的数字太大!') continue elif int(get_area) == len(area_index)-1: print('返回到上级菜单...') break else: chose_area = area_index[int(get_area)][1] print(city_dict[chose_city][chose_area]) print('------------------')
总结:
1.在Python中enumerate的用法多用于在for循环中得到计数,对于一个可迭代的(iterable)/可遍历的对象(如列表、字符串),enumerate将其组成一个索引序列,利用它可以同时获得索引和值
2.没搞明白 print(' ') 为什么有换行的作用...
3. isdigit() 只有为正整数时返回True 其他情况下都返回False
4.
list = [(2, 6), (3, 5), (4, 2)]print(list[1][0])list = [1, 2, 3]print(list[1])tuple = ([1, 2], 5, [3, 4])print(tuple[2])print(tuple[2][1])dict = {'a': {1: 2}, 'b': 2, 'c': 3}print(dict.keys(), dict.values())print(dict['a'])print(dict['a'][1])
32[3, 4]4dict_keys(['a', 'b', 'c']) dict_values([{1: 2}, 2, 3]){1: 2}2
阅读全文
1 0
- 2.多级菜单
- 菜单多级
- 多级菜单
- 多级菜单
- 多级菜单
- 多级菜单
- 多级树型菜单
- asp 多级菜单(美化)
- 多级级联菜单
- 多级下拉菜单(动态)
- 动态生成多级菜单
- 多级树形菜单设计
- 多级联动数据库菜单
- 多级右键菜单
- 动态生成多级菜单
- 多级右键菜单 JS
- CSS多级下拉菜单
- 自定义多级菜单
- Qt阴影效果
- HDOJ 3018-Ant Trip
- POJ 2778 AC自动机+矩阵快速幂
- java面向对象的各种关系总结(UML)
- 关于递归的总结——汉诺塔、素因数的求解(Python实现)
- 2.多级菜单
- HDU6092 Rikka with Subset【DP】
- 关于AndroidStudio的快捷键使用
- CodeForces
- 排序算法五——堆排序
- 8.9上课感悟
- 接口作为类型使用
- Lintcode103 Linked List Cycle || solution 题解
- Java并发编程:Synchronized底层优化(偏向锁、轻量级锁)