计算总税和营业税

时间:2019-02-16 04:19:32

标签: python python-3.x

我是Python的新手,需要作业方面的帮助。

编写一个程序,询问每个商品的价格,然后显示销售,税金和总计的小计。

item1 = float(input("Enter Price of item 1 = $"))
item2 = float(input("Enter Price of item 2 = $"))
item3 = float(input("Enter Price of item 3 = $"))
item4 = float(input("Enter Price of item 4 = $"))
item5 = float(input("Enter Price of item 5 = $"))
subTotal = ("item1 + item2 + item3 + item4 +item5")
tax = 0.07 * subTotal
total = subTotal + tax

我收到此错误消息:

tax = 0.07 * subTotal
TypeError: can't multiply sequence by non-int of type 'float'

1 个答案:

答案 0 :(得分:1)

您收到该错误,是因为您尝试将字符串(即非整数类型)乘以0.07。从subTotal行中删除报价。

item1 = float(input("Enter Price of item 1 = $"))
item2 = float(input("Enter Price of item 2 = $"))
item3 = float(input("Enter Price of item 3 = $"))
item4 = float(input("Enter Price of item 4 = $"))
item5 = float(input("Enter Price of item 5 = $"))
subTotal = (item1 + item2 + item3 + item4 +item5)
tax = 0.07 * subTotal
total = subTotal + tax