如何解决此“ TypeError:'str'对象不可调用”错误?

我正在创建一个基本程序,该程序将使用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`

为什么会出现此错误?


开满天机
浏览 165回答 2
2回答

守着一只汪

我正在创建一个基本程序,该程序将使用GUI来获取商品的价格,如果初始价格小于10,则从价格中减去10%,如果初始价格为10,则从价格中减去20%。大于十:import easyguiprice=easygui.enterbox("What is the price of the item?")if float(price) < 10:&nbsp; &nbsp; easygui.msgbox("Your new price is: $"(float(price) * 0.1))elif float(price) > 10:&nbsp; &nbsp; 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`为什么会出现此错误?

达令说

这部分 :"Your new price is: $"(float(price) 要求python调用此字符串:"Your new price is: $"就像您将要使用的函数一样:&nbsp;function( some_args) &nbsp;它将始终触发错误:TypeError: 'str' object is not callable
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python