Python 初學第三講 — 條件判斷

?????????????

Note: input()?????????????????????????????? input() ???????? string ?

2. if-else??

if ??????? else ???????? if ??????????? else ??????????????????????????????????????????????

if condition: statement1 for True conditionelse: statement2 for False condition

????????condition ?? (True)???? statement1???????statement2????

score = int(input(“score:”))if score >= 60: print(“????!”)else: print(“???????!”)

???????

???????? 60 ???? if ???????????????!??

?????? else ????????????????!??

??????????????????????????

a = input(“a: “)b = input(“b: “)if a > b: print(“max: “, a)else: print(“max: “, b)

???????

if-else?????

3. if-elif-else??

??????????????????????????? if-elif-else ????????????????

if condition1: statement1 for True Condition1elif condition2 : statement2 for True Condition2elif condition3 : statement3 for True Condition3else: statements for Each Condition False

Note: elif ??????????????????????

??????????? A, B, C, D ? F ? 5 ???????

score = int(input(“score: “))if score >= 90: print(‘Grade is: A’)elif score >= 80: print(‘Grade is: B’)elif score >= 70: print(‘Grade is: C’)elif score >= 60: print(‘Grade is: D’)else: print(‘Grade is: F’)

???????

if-elif-else???

4. ??if??

?????????????????????????????? if ????????? if ????? if-else ?????????? if-else ??????

ID = input()year = int(ID[1:3])if year < 4: print(“Graduated”)elif year <= 7 and year >= 4: if year == 7: print(“Freshman”) elif year == 6: print(“Sophomore”) elif year == 5: print(“Junior”) elif year == 4: print(“Senior”)else: print(“Not Registered Yet”)

???????

????????????????????????????????~

???????????????? ? ???

??????????????????????????????????????????????????????

??? ccClub ??????? Python ?????????????????????????????????????????????????????????? 1~10 ??????????Python?????????????? 11 ??????? Facebook: ccClub Python???