Python TypeError: unsupported operand type(s) for /: str and float

Python TypeError: unsupported operand type(s) for /: str and float

Instead of this

total=tef+tpf-price

Try this, I hope this will help you

total=float(tef)+float(float)tpf-float(price)

I think you might take users 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).

Python TypeError: unsupported operand type(s) for /: str and float

One simple way to fix it is:

tef=float(price)*5/100.0

Leave a Reply

Your email address will not be published. Required fields are marked *