我是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' % …Run Code Online (Sandbox Code Playgroud) python ×1