Error: function() takes at least n arguments (n given)

a 夏天 提交于 2019-12-01 16:19:33

When you get an error message that indicates Python can't count arguments, it's generally because the number of arguments you've passed is equal to the number of required arguments, but you're missing some required arguments and including some optional arguments. In this case, you have the following definition:

def integrate(f, z, gamma, t, lower, upper, exact=True):

and the following call:

integrate(f, z, gamma, 0, 2*sy.pi, exact=True)

If we line them up, we see

def integrate(f, z, gamma, t, lower, upper, exact=True):

    integrate(f, z, gamma, 0, 2*sy.pi,      exact=True)

that you're missing one of lower, upper, or t, but because you've supplied exact, the error reporting gets confused.

Python 3 has a better error message for things like this:

>>> def f(a, b=0): pass
... 
>>> f(b=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() missing 1 required positional argument: 'a'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!