Python 类型错误:can';t将序列乘以类型为'的非整数;浮动';错误I';我什么都试过了 询问总价、税金和小费。然后将它们相加,得出总价。
我读了很多文章,但我无法修复。有人能帮我吗?读取的输入是一个字符串,这是一个序列,不能被浮点数乘以Python 类型错误:can';t将序列乘以类型为'的非整数;浮动';错误I';我什么都试过了 询问总价、税金和小费。然后将它们相加,得出总价。,python,python-3.x,syntax,Python,Python 3.x,Syntax,我读了很多文章,但我无法修复。有人能帮我吗?读取的输入是一个字符串,这是一个序列,不能被浮点数乘以 int(price) 解决它。Python3函数返回一个字符串 您已尝试float*string+string+string total= price*percentage + price + tip TypeError: unsupported operand type(s) for +: 'float' and 'str' 你可以这样修理 from time import sleep
int(price)
解决它。Python3函数返回一个字符串
您已尝试float*string+string+string
total= price*percentage + price + tip
TypeError: unsupported operand type(s) for +: 'float' and 'str'
你可以这样修理
from time import sleep
def getprice():
return float(input("What's the price of your bill?").lower())
price = getprice()
def gettax():
return float(input("What's the restaurant's tax percent?").lower())
tax = gettax()
def gettip():
return float(input("How much tip do you want to leave?"))
tip = gettip()
percentage = tax / 100
total= price*percentage + price + tip
print(total)
是的,你需要把corrs变量转换成int或float。非常感谢,我终于明白我的错误了。我很笨,谢谢!
from time import sleep
def getprice():
return float(input("What's the price of your bill?").lower())
price = getprice()
def gettax():
return float(input("What's the restaurant's tax percent?").lower())
tax = gettax()
def gettip():
return float(input("How much tip do you want to leave?"))
tip = gettip()
percentage = tax / 100
total= price*percentage + price + tip
print(total)