我是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'
答案 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