(4) if內又有if
#單價、數量、折價卷
price=120
amount=50
coupon=True
#計算總金額
total = price * amount
#總金額大於2000元先打9折, 如果又有折價卷再扣200元.
#(假設折價卷只能在總金額大於2000元時使用)
if total > 2000:
total = int(total*0.9) #打9折
if coupon:
total -= 200 #扣200元
#顯示應付金額
print(f'{total:,}元')5,200元

2. 加入else指令


自主練習
Last updated