(3) if與else
1. 條件成立與不成立都只有一行指令
#購買總金額
total = 120*40
#超過1000元可打9折, 否則打95折
if total > 1000:
total = int(total*0.9)
else:
total = int(total*0.95)
#印出應付金額
print(f'應付金額{total:,}元')應付金額4,320元

2. 條件成立與不成立有多行指令

自主練習
Last updated