Python implements methods of Fibonacci recursive functions

  • 2020-04-02 14:06:35
  • OfStack

In this paper, a simple example of python implementation of Fibonacci sequence recursive function method, the code is simple and easy to understand. Share with you for your reference.

The main function code is as follows:


def fab(n):
  if n==1:
    return 1
  if n==0:
    return 0
  else:
    result=int(fab(n-1))+int(fab(n-2))    
    return result

The test code is as follows:


for i in range(10):
  print fab(i)

I hope that this article has helped you to learn Python programming.


Related articles: