[英]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)
我在 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)
这应该有效:
################### 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
您的代码有几个我必须修复的错误:
customer_one_total
设置为""
来初始化它lovely_loveseat_price
作为str
添加到customer_one_total
sales_tax
不应设置为int(.884)
,它仅为零。 根据您的评论,您希望它是.088
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.