2014-09-04 98 views
-4

這是我第一次使用python,我不知道如何解決這個問題。TypeError:無法連接'str'和'int'對象需要幫助修復

ItemName = 0.0 
Pounds = 0.0 
Ounces = 0.0 
Unit_Price = 0.0 
Pound_Price = 0.0 
Total_Price = 0.0 

ItemName = raw_input("Enter ItemName") 
Pounds = int(input("Enter amount of Pounds")) 
Ounces = int(input("Enter amuont of Ounces")) 
Pound_Price = int(input("Enter Pound_Price")) 
Unit_Price = int(input("Enter Unit_Price")) 

Total_Price = Pound_Price * (Pounds + Ounces/16) 

print("Item name is: " + ItemName) 
print("Your Unit price is: $" + Unit_Price) 
print("Your Total Comes To: $" + Total_Price) 

當我把所有東西都放下時,它給我輸入錯誤。

+0

@Yugo你看了這個錯誤嗎?它說,「不能連接'str'和'int'對象」。如果這是混淆連接意味着放在一起(通常與+符號),'str'是一個字符串,如「項目名稱」和int是一個數字。如果你想知道你做錯了什麼,你可能只是讀了錯誤。你連接了一個字符串和int對象,但python不允許你。 – 2014-09-04 22:07:37

回答

0

使用.format代替:

print("Item name is: {0}".format(ItemName)) 
print("Your Unit price is: ${0}".format(Unit_Price)) 
print("Your Total Comes To: ${0}".format(Total_Price))