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
Your wabbits() function takes two arguments:
def wabbits(n, k):
# 1 2
but your code calls it with just one:
return wabbits(n-2)*k + wabbits(n-1)
# ^^^ ^^^^
You need to pass in a value for k as well. You could just pass in the current value of k:
def wabbits(n, k):
if n == 1:
return 1
if n == 2:
return 1
return wabbits(n-2, k)*k + wabbits(n-1, k)
# 1 2 1 2
and indeed that produces 19:
>>> def wabbits(n, k):
... if n == 1:
... return 1
... if n == 2:
... return 1
... return wabbits(n-2, k)*k + wabbits(n-1, k)
...
>>> wabbits(5, 3)
19