Jump to content

A NameError: I still cant understand or fix after an hour

So..maybe this isn;t the right place to ask this, but I have been completely stumped, and really annoyed because I cant get this code to work even through a video guide, a post on codeacademy, and a lot of staring at the screen..But im taking a few courses on codeacademy for python, and im doing the project "Lovely loveseats" (ill leave a link to it at the bottom of the post if you want to see it), and I cant understand what im doing wrong or what this error message is pointing out

im coming up with a
“NameError: name ‘customer_one_tax’ is not defined”
with this code and, i’m still confused on what im doing wrong with defining this varible >.<

Here’s the section of code this is associated with and the error is on line 1, all of the varibles not defined here are defined somewhere else in the code, and I can put the full code I have typed in a comment if someone wants to see it (it's only 41 lines long so not alot to read through if i do post it)

 

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 Items”)
print(customer_one_itemization)
print(“Customer one Total”)
print(customer_one_total)

 

And here’s the error message that pops up in the console

Traceback (most recent call last):
File “script.py”, line 19, in
customer_one_total = lovely_loveseat_price + Luxurious_lamp_price + customer_one_tax
NameError: name ‘customer_one_tax’ is not defined

And im completely confused .-. any help would be greatly appreciated !

 

 

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

 

 

Thanks again for real! and sorry if this is kind of an akeward post :/

 

Link to comment
Share on other sites

Link to post
Share on other sites

Post the entire code.

but formatted like this please

Although, from what I see here, you're using customer_one_tax  to calculate customer_one_total  before you're giving it a value.

Ryzen 5 1600 @ 3.9 Ghz  | Gigabyte AB350M Gaming 3 |  PaliT GTX 1050Ti  |  8gb Kingston HyperX Fury @ 2933 Mhz  |  Corsair CX550m  |  1 TB WD Blue HDD


Inside some old case I found lying around.

 

Link to comment
Share on other sites

Link to post
Share on other sites

#Catalog_________________________________________________________

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______________________________________________________

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 Items")
print(customer_one_itemization)
print("Customer one Total")
print(customer_one_total)

#Customer two____________________________________________________

customer_two_total = stylish_settee_price + Luxurious_lamp_price + customer_two_tax

customer_two_itemization += stylish_settee_description + Luxurious_lamp_description

customer_two_tax = customer_two_total * sales_tax

print("Customer two Items")
print(customer_two_itemization)
print("Customer two Total")
print(customer_two_total)







Sorry for forgetting to do that in the last post :S

 

and error message

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

 

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Lumen15 said:

-snip-

 

Okay you're using a variable before it has any value here:


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

customer_one_tax is not yet defined nor initialized when you used it to calculate customer_one_total.

Just move the initialization of customer_one_tax above the customer_one_total.

 

Apologies for if "define" or "initialize" aren't the proper terms in python, I'm a Java programmer.


Edit: My solution will actually also produce the same error because now customer_one_total will be the one undefined. Why are you using customer_one_tax to computer customer_one_total? Are you sure it's not supposed to be sales_tax?

Ryzen 5 1600 @ 3.9 Ghz  | Gigabyte AB350M Gaming 3 |  PaliT GTX 1050Ti  |  8gb Kingston HyperX Fury @ 2933 Mhz  |  Corsair CX550m  |  1 TB WD Blue HDD


Inside some old case I found lying around.

 

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, bleedblue said:

Okay you're using a variable before it has any value here:


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

customer_one_tax is not yet defined nor initialized when you used it to calculate customer_one_total.

Just move the initialization of customer_one_tax above the customer_one_total.

 

Apologies for if "define" or "initialize" aren't the proper terms in python, I'm a Java programmer.


Edit: My solution will actually also produce the same error. Why are you using customer_one_tax to computer customer_one_total? Are you sure it's not supposed to be sales_tax?

Strange, but it worked!

And I thought about moving the varibles above and below each other but like you said it got the same error, but your right, replacing the customer_sales_tax and just * sales_tax with the total works the same way and doesnt produce and error and it prints everything! Thank you :3

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Lumen15 said:

 

 

t2ma1ja3zb201.png

Ryzen 5 1600 @ 3.9 Ghz  | Gigabyte AB350M Gaming 3 |  PaliT GTX 1050Ti  |  8gb Kingston HyperX Fury @ 2933 Mhz  |  Corsair CX550m  |  1 TB WD Blue HDD


Inside some old case I found lying around.

 

Link to comment
Share on other sites

Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

×