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)
它给了我和总行=错误,我读了很多文章,但是我无法修复它可以帮助我吗?
答案 0 :(得分:0)
输入读取是一个字符串,即一个序列,不能由浮点数复制。
int(price)
解决它。
答案 1 :(得分:0)
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)