41. Control Flow and If Statement

Untitled

什麼是控制流程 Control Flow?

  1. 程式碼執行的順序
  2. python 程式是由 conditional statement (if statement)、loops、function calls 控制

If Statement

Untitled

Untitled

使用時機

語法

if False:
		print("This is so true!")
else:
		print("This is false.")

#------------------------------------
# <8 =>free
# >=8 and <65 =>300
# >= 65 =>half

age = 15
if age < 8:
		print("Movie is free for you!")
elif 8 <= age < 65:                   # else if
		print("You need to pay $300!")
else:
		print("You only need to pay $150!")

#------------------------------------
if (5 > 3) and []:                    # []=false
		print("the condition is true")
else:
		print("the condition is false")

#------------------------------------
k = True
if k:
		print("Variable k is true")
else:
		print("Variable k is false")

42. Breakfast Program

Untitled

name = input("Enter your name:") # 抓到的東西都是 String
money = input("Enter your cash amount:")
money = input("Are you hungry> (Y/N)")

如何執行程式碼?

CMD

  1. 開啟 windows CMD