Home > Mobile >  Variable in python not working, can someone tell me what is wrong with my code?
Variable in python not working, can someone tell me what is wrong with my code?

Time:04-07

Can someone assist me in fixing my code, I am new to python and learning the basics however I cannot figure out why I cannot get the "tax" section to print a value? even after following the tutorial step by step.

Full script:

################### Item Descriptions ###################

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_description = 180.50

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

################### Total Formulas ###################

sales_tax = int(.884)

customer_one_itemization = "Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white."
customer_one_total = " "
customer_one_total  = str(lovely_loveseat_price)
customer_one_tax = customer_one_total * sales_tax

################### Prints ###################

print("Customer One Items")
print(customer_one_itemization)
print("Customer One Total")
print(customer_one_total)
print("Customer tax Total")
print(customer_one_tax)

I get the following in the output:

Customer One Items
Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.
Customer One Total
 254.0
Customer tax Total
(THIS SHOULD PRINT THE TAX TOTAL)

CodePudding user response:

This should work:

################### Item Descriptions ###################

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_description = 180.50

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

################### Total Formulas ###################

sales_tax = .088

customer_one_itemization = "Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white."
customer_one_total = lovely_loveseat_price
customer_one_tax = customer_one_total * sales_tax

################### Prints ###################

print("Customer One Items")
print(customer_one_itemization)
print("Customer One Total")
print(customer_one_total)
print("Customer tax Total")
print(customer_one_tax)

Output:

Customer One Items
Lovely Loveseat. Tufted polyester blend on wood. 32 inches high x 40 inches wide x 30 inches deep. Red or white.
Customer One Total
254.0
Customer tax Total
22.352

Your code had several errors that I had to fix:

  • You initialize customer_one_total by setting it equal to ""
  • lovely_loveseat_price is added to customer_one_total as a str
  • sales_tax should not be set to int(.884) which is just zero. According to your comment you want it to be .088
  • Related