Fibonacci Measurement Algorithm implementation: missing 1 required positional argument: 'p'

Question:

I’ve implemented a fibonacci Measurement algorithm with 2 parameter n and p.

I got this issue,

TypeError                                 Traceback (most recent call last)
<ipython-input-19-295638b26e62> in <module>
      2 N = 10
      3 # [F(n,p) for n in range(N)]
----> 4 print(F(10,1))

<ipython-input-12-fda62c8ec9a6> in F(n, p)
      6     elif n <= p+1:
      7       return n
----> 8     return F(n-1) + F(n-p-1)

TypeError: F() missing 1 required positional argument: 'p'

I have input 2 parameters n =10, p = 1, but still having this problem "missing 1 required argument". Does anyone know why and solution for this or any suggestion would be appreciated!

Asked By: Mark Nguyen

||

Answers:

There could be two potential issues.

  1. You’re calling a function, F, that doesn’t seem to be defined in the snippet you’ve attached. You might want to change it to fibonacci_of if it is supposed to call itself recursively. In addition, since the fibonacci_of accepts two parameters, you would need to call it with two arguments
  2. If F is already defined elsewhere, it is supposed to accept more than one argument. You could check its function definition and see the parameter requirements. See attached examples.
def square(a): # Requires single parameter.
  return a ** 2
def add(a, b): # Requires two parameters.
  return a + b
Answered By: Preet Mishra
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.