簡體   English   中英

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)

我在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM