Why given 2 arguments, TypeError: takes exactly 2 arguments (1 given)?

1.2k views Asked by At

I do not know why my function that takes two arguments, when given two arguments, returns an error that says I have only have given one argument. I am trying to get the output of a fibonacci algorithm then multiply that by the second user input.

Thanks

 29 def population(n,k):
 30     n = int(sys.argv[1])
 31     k = int(sys.argv[2])
 32 
 33     if n in range (1,10000):
 34         pass
 35     else:
 36         print("day out of range")
 37     if k in range(1,10000):
 38         pass
 39     else:
 40         print("growth rate out of range")
 41     FibArray = [0,1]
 42 
 43     #reproduction rate is Fn=F(n-1)+F)n-2)
 44     #start fibonacci sequence on one and end on the nth day, multiply by the rate or reproduction
 45     while len(FibArray) < n + 1:
 46         FibArray.append(0)
 47 
 48     if n <=1:
 49         return n
 50     else:
 51         if FibArray [int(n)-1]==0:
 52             FibArray[n-1]=population(n-1)
 53 
 54         if FibArray[n-2]==0:
 55             FibArray[n-2]=population(n-2)
 56 
 57     FibArray[n]= FibArray[n-2] + FibArray[n-1]
 58     X = FibArray[n]
 59     return k * X
 60 
 61 if __name__=="__main__":
 62     n = int(sys.argv[1])
 63     k = int(sys.argv[2])
 64     pop = population(n, k)
 65     print("Your population size on day {} is {}".format(n,pop))




Traceback (most recent call last):
  File "./fibonacci.py", line 64, in <module>
    pop = population(n, k)
  File "./fibonacci.py", line 55, in population
    FibArray[n-2]=population(n-2)
TypeError: population() takes exactly 2 arguments (1 given)
1

There are 1 answers

1
Rutvik Trivedi On

To answer your question, I would say that you read the error again. It says that the error is on line 55, where you have called the population() function with only one argument that is (n-2). That is creating a problem. You need to rectify your code there.