1 ##if陳述句 2 arr=['hello','audi','subaru','toyota'] 3 4 for element in arr: 5 if element=='audi': 6 print(element.upper())##所有字符大寫 7 else: 8 print(element.title())##首字母大寫 9 10 ##and or not 與或非 11 ##檢查特定值是否不包含在串列中 12 num_arr=[num for num in range(1,21,2)] 13 print(num_arr) 14 print('輸入元素并開始判斷') 15 flag=input() 16 print(type(flag))##剛剛才知道input()得到的值是str型別的 17 print(type(num_arr[0])) 18 if int(flag) not in num_arr: 19 print('該串列沒有',flag,'這個元素!') 20 else: 21 print('該元素在串列中!') 22 23 ##if-elif-else 24 print('輸入年齡:') 25 age=int(input()) 26 print(age,type(age))##將input()得到的值成功轉化為int型別 27 if age<2: 28 print('他是一個嬰兒!') 29 elif age>=2 and age <4: 30 print('正在蹣跚學步!') 31 elif age>=4 and age<13: 32 print('他還是個孩子!') 33 elif age>=13 and age<20: 34 print('風華正茂,意氣風發!') 35 elif age>=20 and age<100: 36 print('他是一個成年人!') 37 else: 38 print('輸入錯誤!') 39
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/149340.html
標籤:Python
上一篇:LeetCode 572. 另一個樹的子樹 | Python
下一篇:python日志模板
