- '''
- 程序: 三级菜单
- 要求:
- 打印省, 市, 县三级菜单
- 可返回上一级
- 可随时退出程序
- '''proviInfo = {" 山西 ":{" 吕梁 ":[" 柳林县 "," 中阳县 "," 临县 "," 古交 "]," 大同 ":[" 小脚县 "," 大大县 "," 小小县 "]
- },
- "云南":{"大理市":["苍山","洱海","大理石"],
- "丽江市":["九天","石盘","天问"]
- }
- }
- while True:
- input1 = input("请输出你要查询的省份:")
- for i in proviInfo[input1] :
- print(i)
- input2 = input("返回上一级: up / 退出查询: N / 继续查询下一级:")
- if input2 == "up":
- continue
- elif input2 =="N":
- break
- else:
- for j in proviInfo[input1][input2] :
- print(j)
- View Code
- # 元组被称为只读列表
- #只能查询, 不能修改
- #列表的切片同样适用于元组
- a = (1,2,3,4,5,6)
- print(a[2])#3
- print(a[2:4])#(3, 4)
- # String 的内置方法
- # st='hello kitty {name} is {age}'
- # print(st.count('l')) # 统计元素个数
- # print(st.capitalize()) # 首字母大写
- # print(st.center(50,'#')) # 居中
- # print(st.endswith('tty3')) # 判断是否以某个内容结尾
- # print(st.startswith('he')) # 判断是否以某个内容开头
- # print(st.expandtabs(tabsize=20))
- # print(st.find('t')) # 查找到第一个元素, 并将索引值返回
- # print(st.format(name='alex',age=37)) # 格式化输出的另一种方式 待定:?:{}
- # print(st.format_map({'name':'alex','age':22}))
- # print(st.index('t'))
- # print('asd'.isalnum())
- # print('12632178'.isdecimal())
- # print('1269999.uuuu'.isnumeric())
- # print('abc'.isidentifier())
- # print('Abc'.islower())
- # print('ABC'.isupper())
- # print('e'.isspace())
- # print('My title'.istitle())
- # print('My tLtle'.lower())
- # print('My tLtle'.upper())
- # print('My tLtle'.swapcase())
- # print('My tLtle'.ljust(50,'*'))
- # print('My tLtle'.rjust(50,'*'))
- # print('\tMy tLtle\n'.strip())
- # print('\tMy tLtle\n'.lstrip())
- # print('\tMy tLtle\n'.rstrip())
- # print('ok')
- # print('My title title'.replace('itle','lesson',1))
- # print('My title title'.rfind('t'))
- # print('My title title'.split('i',1))
- # print('My title title'.title())
- # 摘一些重要的字符串方法
- #1 print(st.count('l'))
- # print(st.center(50,'#')) # 居中
- # print(st.startswith('he')) # 判断是否以某个内容开头
- # print(st.find('t'))
- # print(st.format(name='alex',age=37)) # 格式化输出的另一种方式 待定:?:{}
- # print('My tLtle'.lower())
- # print('My tLtle'.upper())
- # print('\tMy tLtle\n'.strip())
- # print('My title title'.replace('itle','lesson',1))
- # print('My title title'.split('i',1))
- # 1 * 重复输出字符串
- # print('hello'*20)
- # 2 [] ,[:] 通过索引获取字符串中字符, 这里和列表的切片操作是相同的, 具体内容见列表
- # print('helloworld'[2:])
- #关键字 in
- # print(123 in [23,45,123])
- # print('e2l' in 'hello')
- # 4 % 格式字符串
- # print('alex is a good teacher')
- # print('%s is a good teacher'%'alex')
- #5
- # a='123'
- # b='abc'
- # d='44'
- # # # c=a+b
- # # # print(c)
- # #
- # c= ''.join([a,b,d])
- # print(c)
- 作业: 程序: 三级菜单
- '''
- 程序: 三级菜单
- 要求:
- 打印省, 市, 县三级菜单
- 可返回上一级
- 可随时退出程序
- '''proviInfo = {" 山西 ":{" 吕梁 ":[" 柳林县 "," 中阳县 "," 临县 "," 古交 "]," 大同 ":[" 小脚县 "," 大大县 "," 小小县 "]
- },
- "云南":{"大理市":["苍山","洱海","大理石"],
- "丽江市":["九天","石盘","天问"]
- }
- }
- while True:
- input1 = input("请输出你要查询的省份:")
- for i in proviInfo[input1] :
- print(i)
- input2 = input("返回上一级: up / 退出查询: N / 继续查询下一级:")
- if input2 == "up":
- continue
- elif input2 =="N":
- break
- else:
- for j in proviInfo[input1][input2] :
- print(j)
- View Code
参考老师的作业:
- http://www.cnblogs.com/alex3714/articles/5717620.html
- python-06
来源: http://www.bubuko.com/infodetail-2644644.html