Python中的打折问题

折扣季某商店清仓销售某款服装,原价499,顾客购买一件打八折,二件打七折,三件打五折,四件及以上打四折,从键盘输入该款服装的数量,输出应付金额和实际消费金融。

n = int(input('购买数量:'))
price=499
discount=0.8
if n>=4:
    discount=0.4
elif n==3:
    discount=0.5
elif n==2:
    discount=0.7
print(f'应付金额:{price*n}')
print(f'实际消费金额:{price*n*discount:.2f}')
n = int(input('购买数量:'))
price = 499.0
discount = [1.0,0.8,0.7,0.5,0.4]
total = n*price*discount[4 if divmod(n,4)[0] else divmod(n,4)[1]]

print(f'应付金额:{price*n:.2f}\n实际消费金额:{total:.2f}')