TypeError in python - missing 1 required positional argument

后端 未结 3 1456
遥遥无期
遥遥无期 2021-01-28 09:31

I\'m stuck here. For n = 5 and k = 3, the answer should be 19. If I set k = 3 separately as a local or global variable and ru

3条回答
  •  既然无缘
    2021-01-28 09:44

    Calling the function with wabbits(5) will not work because the function is declared to accept 2 parameters: n and k. Both must be supplied.

    You can call the function with two arguments, but the trouble is that the recursive call to wabbits() passes only a single argument:

    wabbits(n-2) * k + wabbits(n-1)
    

    This is two calls to wabbits() the first has one argument n-2 and the second also has only one argument n-1. Since wabbits() must be called with two arguments a TypeError` exception is raised as you observed.

提交回复
热议问题