Try   HackMD

影片大綱

  1. if 判斷式
    1.1 單一判斷:if
    1.2 雙向判斷:if else
    1.3 多條件判斷:if elif else

  2. 補充資訊
    2.1 不支援 switch 判斷式 ( 3.6 版 )
    2.2 使用 tab 做縮排,表達判斷式中的執行命令。
    2.3 試著自己獨立完成練習。

影片

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

筆記

if 布林值:
    若布林值為 True,執行命令
if 布林值:
    若布林值為 True,執行命令
else:
    若布林值為 False,執行命令
if 布林值一:
    若布林值一為 True,執行命令
elif 布林值二:
    若布林值二為 True,執行命令
if 布林值一:
    若布林值一為 True,執行命令
elif 布林值二:
    若布林值二為 True,執行命令
else:
    若布林值一和布林值二都 False,執行命令

程式範例

x=input("請輸入數字:") # 基本輸入為字串型態
x=int(x) # 轉換為整數型態
if x>200:
print("大於 200")
elif x>100:
print("大於 100,小於200")
else:
print("小於 100")


YT留言

Part 1:
# 判斷式
if True:
   print("True 執行")
else:
   print("False 執行")

Part 2:
x=input("請輸入數字︰") # 取得字串形式的使用者輸入
x=int(x) # 將字串型態轉換成數字型態
if x>200:
    print("大於 200")
elif x>100:
    print("大於 100,小於等於 200")
else:
    print("小於等於 100")

Part 3:
# 四則運算
n1=int(input("請輸入數字一︰"))
n2=int(input("請輸入數字二︰"))
op=input("請輸入運算︰+, -, *, /:")
if op=="+":
    print(n1+n2)
elif op=="-":
    print(n1-n2)
elif op=="*":
    print(n1*n2)
elif op=="/":
    print(n1/n2)
else:
    print("不支援的運算")

END