'extreme beginner to python, cant understand an error [closed]
super new to python and having an error on one of my codecademy projects that i cant seem to understand, even referencing the walkthrough and altering line 17 multiple times i cant quiet understand why this is returning an error. could somebody help me understand the error so i can learn from it? this is my code thats returning a type error:
lovely_loveseat_description = """Lovely Loveseat. Tufted polyester blend on wood. 32 inches high X 40 inches wide X 30 inches deep. Available in Red or White."""
lovely_loveseat_price = 254.00
stylish_setee_description = """Stylish Settee. Faux leather on birch.
29.50 inches high X 54.75 inches wide X 28 inches deep. Available only in Black."""
stylish_settee_price = 150.50
luxurious_lamp_description = "Luxurious Lamp. Glass and iron. 36 inches tall. Available in Brown with a Stylish Beige shade."
luxurious_lamp_price = 52.15
#sales tax variable.
sales_tax = .088
#base shopping cart total value.
customer_one_total = 0
#shopping cart contents variable.
customer_one_itemization = ""
#shopping area.
customer_one_total =+ lovely_loveseat_price
customer_one_itemization =+ lovely_loveseat_description
customer_one_total =+ luxurious_lamp_price
customer_one_itemization =+ luxurious_lamp_description
customer_one_tax = customer_one_total * sales_tax
customer_one_total =+ customer_one_tax
print("Customer One Items:")
print(customer_one_itemization)
print("Customer One Total Cost:")
print(customer_one_total)```
and this is the error:
```Traceback (most recent call last):
File "script.py", line 17, in <module>
customer_one_itemization =+ lovely_loveseat_description
TypeError: bad operand type for unary +: 'str'```
thanks heaps guys.
Solution 1:[1]
>>> a = "hello"
>>> b = "bye"
>>> a =+ b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: bad operand type for unary +: 'str'
>>> a += b
>>> a
'hellobye'
Cannot do =+ like that on strings
Solution 2:[2]
The correct syntax is += not =+
lovely_loveseat_description = """Lovely Loveseat. Tufted polyester blend on wood. 32 inches high X 40 inches wide X 30 inches deep. Available in Red or White."""
lovely_loveseat_price = 254.00
stylish_setee_description = """Stylish Settee. Faux leather on birch.
29.50 inches high X 54.75 inches wide X 28 inches deep. Available only in Black."""
stylish_settee_price = 150.50
luxurious_lamp_description = "Luxurious Lamp. Glass and iron. 36 inches tall. Available in Brown with a Stylish Beige shade."
luxurious_lamp_price = 52.15
#sales tax variable.
sales_tax = .088
#base shopping cart total value.
customer_one_total = 0
#shopping cart contents variable.
customer_one_itemization = ""
#shopping area.
customer_one_total += lovely_loveseat_price
customer_one_itemization += lovely_loveseat_description
customer_one_total += luxurious_lamp_price
customer_one_itemization += luxurious_lamp_description
customer_one_tax = customer_one_total * sales_tax
customer_one_total += customer_one_tax
print("Customer One Items:")
print(customer_one_itemization)
print("Customer One Total Cost:")
print(customer_one_total)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sam Creamer |
| Solution 2 | Alberto Hanna |
