[英]I'm getting this error but I tried everything. TypeError: can't multiply sequence by non-int of type 'float'
[英]TypeError: can't multiply sequence by non-int of type 'float' error I've tried everything
from time import sleep
def getprice():
return input("What's the price of your bill?").lower()
price = getprice()
def gettax():
return input("What's the restaurant's tax percent?").lower()
tax = gettax()
def gettip():
return input("How much tip do you want to leave?")
tip = gettip()
percentage = float(tax)/100
total= price*percentage + price + tip
print(total)
它给了我并在total =行上出错,我读了许多文章,但我无法解决,有人可以帮助我吗?
读取的输入是一个字符串,即一个序列,不能与浮点数相乘。
int(price)
解决它。
Python3 input
函数返回一个字符串。
您尝试过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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.