【发布时间】:2010-12-30 21:26:30
【问题描述】:
我是 Python 的菜鸟,我没有任何运气来解决这个问题。我希望能够将税收变量保留在代码中,以便在更改时轻松更新。我尝试了不同的方法,但只能让它跳过打印税行并为总计和小计打印相同的值。如何将税收变量乘以 sum(items_count)?代码如下:
items_count = []
tax = float(.06)
y = 0
count = raw_input('How many items do you have? ')
while count > 0:
price = float(raw_input('Please enter the price of your item: '))
items_count.append(price)
count = int(count) - 1
print 'The subtotal of your items is: ' '$%.2f' % sum(items_count)
print 'The amount of sales tax is: ' '$%.2f' % sum(items_count) * tax
total = (sum(items_count) * tax) + sum(items_count)
print 'The total of your items is: ' '$%.2f' % total
【问题讨论】:
-
能否请您重新粘贴您的代码,使其完全格式化为代码。暂时无法阅读。谢谢!
-
感谢大家回答我的问题。 @steveha,很好的解释,是的,我第一次编写代码时 y 变量实际上是有意义的。 @Kimvais,感谢您为我清理代码。
标签: python