尝试调用tax()TypeError时出错:“int”对象不是callab

2024-09-29 21:49:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习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)

Tags: ofinnumberinputyour错误daysone
1条回答
网友
1楼 · 发布于 2024-09-29 21:49:19

tax不是可调用的(具有__call__方法的对象)

所以你不能叫它

在将它定义为函数之前,tax是一个输入返回,因此是一个字符串

不能像调用函数那样调用它(例如)

如一些注释所述,您应该在尝试调用tax()函数之前定义它,并且不应该使用tax作为其他变量的名称

相关问题 更多 >

    热门问题