码迷,mamicode.com
首页 > 编程语言 > 详细

python-06

时间:2018-06-14 22:17:02      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:world   inpu   asd   lse   分享   continue   ==   tar   strip   


技术分享图片
 1 ‘‘‘
 2 程序: 三级菜单
 3 
 4 要求:
 5 
 6 打印省、市、县三级菜单
 7 可返回上一级
 8 可随时退出程序
 9 ‘‘‘
10 
11 proviInfo = {
12     "山西":{"吕梁":["柳林县","中阳县","临县","古交"],
13              "大同":["小脚县","大大县","小小县"]
14           },
15     "云南":{"大理市":["苍山","洱海","大理石"],
16             "丽江市":["九天","石盘","天问"]
17           }
18 }
19 
20 while True:
21     input1 = input("请输出你要查询的省份:")
22     for i in proviInfo[input1] :
23         print(i)
24     input2 = input("返回上一级:up/退出查询:N/继续查询下一级:")
25     if input2 == "up":
26         continue
27     elif input2 =="N":
28         break
29     else:
30         for j in  proviInfo[input1][input2] :
31             print(j)
View Code

 

1 #元组被称为只读列表
2 #只能查询,不能修改
3 #列表的切片同样适用于元组
4 a = (1,2,3,4,5,6)
5 print(a[2])#3
6 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 # 1   * 重复输出字符串
 2 # print(‘hello‘*20)
 3 
 4 # 2 [] ,[:] 通过索引获取字符串中字符,这里和列表的切片操作是相同的,具体内容见列表
 5 # print(‘helloworld‘[2:])
 6 
 7 #关键字 in
 8 # print(123 in [23,45,123])
 9 # print(‘e2l‘ in ‘hello‘)
10 
11 # 4 %   格式字符串
12 # print(‘alex is a good teacher‘)
13 # print(‘%s is a good teacher‘%‘alex‘)
14 
15 #5
16 # a=‘123‘
17 # b=‘abc‘
18 # d=‘44‘
19 # # # c=a+b
20 # # # print(c)
21 # #
22 # c= ‘‘.join([a,b,d])
23 # print(c)

 作业:程序: 三级菜单

技术分享图片
 1 ‘‘‘
 2 程序: 三级菜单
 3 
 4 要求:
 5 
 6 打印省、市、县三级菜单
 7 可返回上一级
 8 可随时退出程序
 9 ‘‘‘
10 
11 proviInfo = {
12     "山西":{"吕梁":["柳林县","中阳县","临县","古交"],
13              "大同":["小脚县","大大县","小小县"]
14           },
15     "云南":{"大理市":["苍山","洱海","大理石"],
16             "丽江市":["九天","石盘","天问"]
17           }
18 }
19 
20 while True:
21     input1 = input("请输出你要查询的省份:")
22     for i in proviInfo[input1] :
23         print(i)
24     input2 = input("返回上一级:up/退出查询:N/继续查询下一级:")
25     if input2 == "up":
26         continue
27     elif input2 =="N":
28         break
29     else:
30         for j in  proviInfo[input1][input2] :
31             print(j)
View Code

参考老师的作业:

http://www.cnblogs.com/alex3714/articles/5717620.html

 

  

python-06

标签:world   inpu   asd   lse   分享   continue   ==   tar   strip   

原文地址:https://www.cnblogs.com/neilyoung22/p/9175537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!