0
這是我的代碼:Python語法錯誤帶有測試代碼
ItemName = input("Enter your item name: ")
PricePerPound = float(input("Enter the Price per pound: "))
ItemWeightPounds = float(input("Enter the weight of the item in pounds: "))
ItemWeightOunces = float(input("Enter the weight of the item in Ounces: "))
UnitPrice = (PricePerPound/16)
TotalPrice = (PricePerPound * ItemWeightPounds + ItemWeightOunces/16)
print("The Unit Price for your " + ItemName + " is: $" + UnitPrice)
print("The Total Price for your " + ItemName + " is: $" + TotalPrice)
Traceback (most recent call last):
print("The Unit Price for your " + ItemName + " is: $" + UnitPrice)
TypeError: Can't convert 'float' object to str implicitly
每當我運行它在python我得到上述錯誤,任何人都可以找出我的代碼的問題是什麼?
我已編輯,這是我現在得到TypeError的錯誤:不能將'float'對象隱式轉換爲str我的最後兩行:print(「您的」+ ItemName +「的單價是:」+ UnitPrice) print(「您的」+ ItemName +「的總價格爲:」「+ TotalPrice) – Atom 2014-09-20 18:27:20
我編輯了我的答案。 – Leistungsabfall 2014-09-20 18:27:43
啊完美,比你!我不知道我必須添加str。 – Atom 2014-09-20 18:30:53