python-06
阿新 • • 發佈:2018-06-15
sde 繼續 play pen pac 技術 bre con iss
1 ‘‘‘ 2 程序: 三級菜單 3 4 要求: 5 6 打印省、市、縣三級菜單 7 可返回上一級 8 可隨時退出程序 9 ‘‘‘ 10 11 proviInfo = { 12 "山西":{"呂梁":["柳林縣","中陽縣","臨縣","古交"], 13 "大同":["小腳縣","大大縣","小小縣"] 14 }, 15 "雲南":{"大理市":["蒼山","洱海","大理石"], 16 "麗江市":["九天","石盤","天問"] 17 } 18 } 19 20View Codewhile 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)
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