python 中的变量不起作用,有人可以告诉我我的代码有什么问题吗?

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

有人可以帮助我修复我的代码,我是 python 的新手,正在学习基础知识,但我不明白为什么我无法让“税”部分打印值?即使按照教程一步步进行。

完整脚本:

################### 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)

我在输出中得到以下内容:

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)

这应该有效:

################### 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)

输出:

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

你的代码有几个我必须修复的错误:

  • 您通过将 customer_one_total 设置为 ""
  • 来初始化它
  • lovely_loveseat_price 作为 str
  • 添加到 customer_one_total
  • sales_tax 不应设置为 int(.884),它只是零。根据您的评论,您希望它是 .088