close

[Solved] Unsupported operand type(s) for +: ‘float’ and ‘str’ error

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Unsupported operand type(s) for +: ‘float’ and ‘str’ error 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 Unsupported operand type(s) for +: ‘float’ and ‘str’ error Error Occurs?

Today I get the following error Unsupported operand type(s) for +: ‘float’ and ‘str’ error in python.

How To Solve Unsupported operand type(s) for +: ‘float’ and ‘str’ error Error ?

  1. How To Solve Unsupported operand type(s) for +: 'float' and 'str' error Error ?

    To Solve Unsupported operand type(s) for +: 'float' and 'str' error Error Since score was created by splitting a string, it's elements are all strings; hence the complaint about trying to add a float to a string.

  2. Unsupported operand type(s) for +: 'float' and 'str' error

    To Solve Unsupported operand type(s) for +: 'float' and 'str' error Error Since score was created by splitting a string, it's elements are all strings; hence the complaint about trying to add a float to a string.

Solution 1

Since score was created by splitting a string, it’s elements are all strings; hence the complaint about trying to add a float to a string. If you want the value that that string represents, you need to compute that; something like float(score[i]).

Solution 2

score is a list of strings, so you definitely cannot add a string to a float as you do here: addedScore = addedScore + score[i]. You have to convert this string to a float: addedScore = addedScore + float(score[i])

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