三、 python筆記控制語句if
阿新 • • 發佈:2019-03-28
bsp som ron 布爾表達式 arr str += dso span
三、 python筆記控制語句if
# if語句
client_balance = 1000 bank_balance = 10000000 print("You have " + str(client_balance) + "RMB in your game balance." + " You have "+str(bank_balance) + "RMB in your bank balance, Tuhao !") if client_balance < 2000: client_balance += 1500 bank_balance -= 1500 print("You have " + str(client_balance) + "RMB in your game balance." + " You have "+str(bank_balance) + "RMB in your bank balance, Tuhao !")
輸出:
You have 1000RMB in your game balance. You have 10000000RMB in your bank balance, Tuhao !
You have 2500RMB in your game balance. You have 9998500RMB in your bank balance, Tuhao !
# if-elif-else判斷
name = "Tony" if name == "Tony": print("Hello Tony") elif name == "Marry": print("Hello Marry") elif name == "Garry": print("Hello Garry") else: print("Go away!")
輸出:
Hello Tony
# 復雜的布爾表達式
# BMI計算
weight = 75 height = 1.85 if18.5 <= weight/height ** 2 <= 25: print("Will, you are in good shape " + " BMI: " + str(weight/height ** 2)) else: print("Will, you need to work harder " + "BMI:" + str(weight/height ** 2))
輸出:
Will, you are in good shape BMI: 21.913805697589478
# 布爾表達式判斷
tall = True rich = True handsome = True if tall and rich and handsome: print("He is the one!") else: print("Pass!")
輸出:
He is the one!
三、 python筆記控制語句if