成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術文章
文章詳情頁

Python多分支if語句的使用

瀏覽:7日期:2022-07-12 14:06:49

注意:if語句代碼是從上往下執(zhí)行的,當執(zhí)行到滿足條件的語句時,代碼會停止往下執(zhí)行

注意:if語句后面要加上冒號

score = int (input('score:'))if score > 90: print('A')elif score > 80: print('B')elif score > 70: print('C')elif score > 60: print('D')else score < 60: print('加油吧孩紙')

補充知識:python之if語句以及條件測試( and 、or、in、not in)

1.and 、or、in、not in

’’’條件測試’’’#單個條件測試age0 = 22print(age0>=22) # True#多個條件測試 andage0 = 22age1 = 18print(age0>=21 and age1>=21) #False#多個條件測試 orprint(age0>=21 or arg0>=21) #True #in和not in(檢查特定值是否在列表中)fruits = [’apple’,’banana’,’orange’]print(’apple’ in fruits) #Trueprint(’apple’ not in fruits) #False

2.if語句

’’’簡單的if語句(僅包含一個測試和一個操作)’’’height = 1.7if height>=1.3: print(’高’)

’’’if-else’’’height = 1.8if height<=1.4: print(’免票’)else: print(’全票’)#最后輸出全票

’’’if-elif’’’height = 1.5if height>=1.4: print(’嘿嘿’)elif height>=1.3: print(’呵呵’)#最后輸出嘿嘿

’’’if-elif-else’’’height = 1.8if height<=1.4: print(’免票’)elif height>1.4 and height<=1.7: print(’半票’)else: print(’全票’)#最后輸出全票

以上這篇Python多分支if語句的使用就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標簽: Python 編程
相關文章: