if
現在該仔細看看你家的環境了。
範例程式碼中定義了兩個變數:room 是字串,表示我們正在看的房間;area 則是該房間的面積。
本練習屬於課程
Python 中級
練習說明
- 檢視
if敘述:當room等於"kit"時,會印出"looking around in the kitchen."。 - 再寫一個
if敘述:當area大於 15 時,印出 "big place!"。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Define variables
room = "kit"
area = 14.0
# if statement for room
if room == "kit" :
print("looking around in the kitchen.")
# if statement for area