Search In
• More options...
Find results that contain...
Find results in...

# Codeacademy (python), what's the point of this variable?

Go to solution Solved by KarathKasun,

It says update the total.

So..

customer_one_total = item1 + item2

customer_one_tax = customer_one_total * sales_tax

customer_one_total = customer_one_total + customer_one_tax

I'm doing the python course and I'm a bit confused as to why the instructions tell you to write the code this way when it produces an error:

```lovely_loveseat_description = """ Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.
"""
lovely_loveseat_price = 254.00

stylish_settee_description = """ Stylish Settee. Faux leather on birch. 29.50 inches high x 54.75 inches wide x 28 inches deep. Black.
"""
stylish_settee_price = 180.50

luxurious_lamp_description = """ Luxurious Lamp. Glass and iron. 36 inches tall. Brown with cream shade.
"""
luxurious_lamp_price = 52.15

sales_tax = .088

customer_one_total = lovely_loveseat_price + luxurious_lamp_price * customer_one_tax

customer_one_itemization = lovely_loveseat_description + luxurious_lamp_description

customer_one_tax = customer_one_total * sales_tax
print(customer_one_itemization)
print("Customer One Total:")
print(customer_one_total)```

"

```Traceback (most recent call last):
File "script.py", line 15, in <module>
customer_one_total = lovely_loveseat_price + luxurious_lamp_price * customer_one_tax
NameError: name 'customer_one_tax' is not defined```

"

I understand why this produces an error, as I'm using a variable not yet defined. However the correct answer is to simply replace "customer_one_tax" in "customer_one_total" with " * sales_tax"

So .. what's the point of the customer_one_tax variable? It's not used anywhere. Confused as to why you're instructed to make that a variable. Maybe I'm stupid and missing something but I really can't figure it out.

Earlier in the course it also says to equal customer_one_itemization to an empty string "" whereas later on it says to equal customer_two_itemization to and empty string (""), are these intentional inconsistencies?

##### Share on other sites

Its failing because customer_one_tax requires customer_one_total which requires customer_one_tax...

The calculations are also not correct.  item1+item2*tax will NOT give the proper answer.  You need (item1+item2)*tax for it to work properly.

I think you may be misinterpreting some of the instructions.

##### Share on other sites

A link to or a description of the exercise would help, as without context the answer could be anything.

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

##### Share on other sites

7 minutes ago, KarathKasun said:

Its failing because customer_one_tax requires customer_one_total which requires customer_one_tax...

The calculations are also not correct.  item1+item2*tax will NOT give the proper answer.  You need (item1+item2)*tax for it to work properly.

I think you may be misinterpreting some of the instructions.

I know that's why it's failing, as I said, but the instructions tell you to do it like that. At least that's how I'm interpreting it. I changed the calculations to your way but it gave the same answer.

##### Share on other sites

It says update the total.

So..

customer_one_total = item1 + item2

customer_one_tax = customer_one_total * sales_tax

customer_one_total = customer_one_total + customer_one_tax

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account