TypeError: unsupported operand type(s) for +=: 'int' and 'str'

Hello! I was go through this lesson

https://www.codecademy.com/paths/computer-science/tracks/cspath-intro/modules/cspath-python-syntax/projects/furniture-store

and faced the error :

TypeError: unsupported operand type(s) for +=: ‘int’ and 'str’

The code is


lovely_loveseat_description = 'text'
lovely_loveseat_price = 254.00

lovely_loveseat_price = 'text'
stylish_settee_price = 180.50

luxurious_lamp_description = 'text'
luxurious_lamp_price = 52.15

sales_tax = .088

customer_one_total = 0
customer_one_itemization = " "

customer_one_total += lovely_loveseat_price
print (customer_one_total)

So it gives an error on that line


customer_one_total += lovely_loveseat_price

and, as I understand it, it’s not working because it’s a numerical type of data. But how can I calculate that data if I change it to a string?

I also watched a walkthrough video and did all the same as in the video and still get this error.

Would be very thankful if you can explain why the error is occurring, what it means and how to fix it.
Or any link where I can get the information :slight_smile:

when adding an integer and string together:

"abc" + 123

what should the result be? I think an error is very sensible here

but i think its also slightly besides the point, you declare the variable as integer:

lovely_loveseat_price = 254.00

but then overwrite it with a string:

lovely_loveseat_price = 'text'

but i think that is a mistake, that variable should be named differently (stylish_settee_description`)

1 Like