Skip to content Skip to sidebar Skip to footer

Typeerror: Unsupported Operand Type(s) For +: 'int' And 'str' Value

I've written a script to work out the value with variable program_width, but I have got a weird error. The error is: TypeError: unsupported operand type(s) for +: 'int' and 'str' T

Solution 1:

You're setting program_width to the string"500" instead of the int500. Then you're trying to add it to the int350. These are different types, and the error is telling you exactly what's wrong, you can't add integers and strings.

My guess is that you want it to be an int from the beginning, so

program_width = "500"

should be

program_width = 500

But if you really want it to be a string for some reason (you almost certainly don't), you can cast the string into an int with the int() function.

program_start = 350 + int(program_width)

Solution 2:

Try this, in all the parts where you're assigning program_width:

program_width = 250

Notice that I removed the "" surrounding the number. Those quotes mean that the value is a string, and you can not add a number to a string, I'm pretty sure that you intended to use program_width as an integer. Now this will work:

program_teststart = 350 + program_width

Post a Comment for "Typeerror: Unsupported Operand Type(s) For +: 'int' And 'str' Value"