Recursive fibonacci function. : recursive function « Function « Python Tutorial






def fibonacci( n ):

   if n < 0: 
      print "Cannot find the fibonacci of a negative number"

   if n == 0 or n == 1:  # base case
      return n
   else:
      return fibonacci( n - 1 ) + fibonacci( n - 2 )

number = int( raw_input( "Enter an integer: " ) )
result = fibonacci( number )
print "Fibonacci(%d) = %d" % ( number, result )








10.13.recursive function
10.13.1.Recursion
10.13.2.Recursive factorial function.
10.13.3.Recursive fibonacci function.
10.13.4.Recursive Functions