[英]Calculating discount on final amount
我写了以下代码
total=0
n=int(input('enter number of items: '))
for i in range(n):
cost=int(input('Please enter a item cost:'))
total+=cost
if total>=1000:
print('Discount of 10%')
total*=0.9
print('final total is',total)
elif total<1000:
print('Discount of 5%')
total*=0.95
print('final total is',total)
我只想计算最终金额的折扣,而不是每个产品的折扣。 如何修改我的代码?
您需要将if-elif
移到 for 循环之外,这在 Python 中只是意味着取消缩进。 然后for
循环将只计算总数,然后在完成后评估条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.