2 回答

TA貢獻1872條經驗 獲得超4個贊
我正在創建一個基本程序,該程序將使用GUI來獲取商品的價格,如果初始價格小于10,則從價格中減去10%,如果初始價格為10,則從價格中減去20%。大于十:
import easygui
price=easygui.enterbox("What is the price of the item?")
if float(price) < 10:
easygui.msgbox("Your new price is: $"(float(price) * 0.1))
elif float(price) > 10:
easygui.msgbox("Your new price is: $"(float(price) * 0.2))
我仍然收到此錯誤:
easygui.msgbox("Your new price is: $"(float(price) * 0.1))
TypeError: 'str' object is not callable`
為什么會出現此錯誤?

TA貢獻1821條經驗 獲得超6個贊
這部分 :
"Your new price is: $"(float(price)
要求python調用此字符串:
"Your new price is: $"
就像您將要使用的函數一樣: function( some_args)
它將始終觸發錯誤:
TypeError: 'str' object is not callable
添加回答
舉報