Python Typeerror: Unsupported Operand Type(s) For /: 'str' And 'float'
My code: total=tef+tpf-price I've got this error: total=tef+tpf-price unsupported operand type(s) for -: 'float' and 'str' How do I fix it?
Solution 1:
Instead of this
total=tef+tpf-price
Try this, I hope this will help you
total=float(tef)+float(float)tpf-float(price)
Solution 2:
I think you might take user's price
input, like:
price = raw_input('--> ') // Python 2.x
or
price = input('--> ') // Python 3.x
So you might want to do some validation before using it.
You could cast price
from string to float by float(price)
.
Solution 3:
One simple way to fix it is:
tef=float(price)*5/100.0
Post a Comment for "Python Typeerror: Unsupported Operand Type(s) For /: 'str' And 'float'"