(5) if...elif
#單價、數量
price=120
amount=50
#計算總金額
total = price * amount
#總金額至少2,000元可打8折,
#若不足2,000元, 但至少1,000元可打9折,
#若不足1,000元, 但至少500元可打95折.
if total >= 2000:
total = int(total*0.8) #打8折
elif total >= 1000:
total = int(total*0.9) #打9折
elif total >= 500:
total = int(total*0.95) #打95折
#顯示應付金額
print(f'{total:,}元')

自主練習
Last updated