我是Python的noob,并且没有任何运气能够弄清楚这一点。我希望能够在代码中保留税收变量,以便在更改时轻松更新。我尝试了不同的方法,但只能让它跳过打印税线,并打印总计和小计的相同值。如何通过sum(items_count)乘以税收变量?下面是代码:TypeError:无法乘以类型为'float'的非整型序列
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
请你重新粘贴你的代码,以便它完全格式化为代码。目前无法阅读。谢谢! – Kimvais 2009-12-29 19:37:11
感谢大家回答我的问题。 @steveha,很好的解释,是的,我第一次写了代码y变量实际上有意义。 @Kimvais,谢谢你为我清理代码。 – Timmay 2009-12-29 23:11:02