close

[Solved] Python TypeError: unsupported operand type(s) for /: ‘str’ and ‘float’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python TypeError: unsupported operand type(s) for /: ‘str’ and ‘float’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python TypeError: unsupported operand type(s) for /: ‘str’ and ‘float’ Error Occurs?

Today I get the following error Python TypeError: unsupported operand type(s) for /: ‘str’ and ‘float’ in python.

How To Solve Python TypeError: unsupported operand type(s) for /: ‘str’ and ‘float’ Error ?

  1. How To Solve Python TypeError: unsupported operand type(s) for /: 'str' and 'float' Error ?

    To Solve Python TypeError: unsupported operand type(s) for /: 'str' and 'float' Error So you might want to do some validation before using it.
    You could cast price from string to float by float(price).

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

    To Solve Python TypeError: unsupported operand type(s) for /: 'str' and 'float' Error So you might want to do some validation before using it.
    You could cast price from string to float by float(price).

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).

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read