我正在学习Python,想尝试创建一个函数,然后调用它。当我运行它时,如果我为“tax”变量输入任何小于1的值,它就会按我所希望的方式工作,但是如果我为tax变量输入一个大于1的值,我会得到一个错误,它说:
TypeError: 'int' object is not callable
我搜索过谷歌,仍然不知道这个错误消息是什么意思,也不知道如何修复它。非常感谢您的帮助
tax = input("Enter your local tax rate: ")
if tax < 1:
hourlyWage = input("Enter your hourly wage: ")
hoursWorked = input("Enter number of hours worked in one day: ")
daysWorked = input("Enter number of days worked in one week: ")
print(hourlyWage * hoursWorked * daysWorked * tax)
else:
tax()
def tax():
hourly = input("Enter your hourly wage: ")
workedHours = input("Enter number of hours worked in one day: ")
days = input("Enter number of days worked in one week: ")
weeklyWage = hourly * workedHours * days
newTax = tax / 100 * weeklyWage
newWeeklyWage = weeklyWage - newTax
print(newWeeklyWage)
tax
不是可调用的(具有__call__
方法的对象)所以你不能叫它
在将它定义为函数之前,
tax
是一个输入返回,因此是一个字符串不能像调用函数那样调用它(例如)
如一些注释所述,您应该在尝试调用
tax()
函数之前定义它,并且不应该使用tax
作为其他变量的名称相关问题 更多 >
编程相关推荐