Fibonacci sequence using functions for N numbers


# Compatible in Python 2.7

def recur_fibo(n):
   if n <= 1:
       return n
   else:
       return(recur_fibo(n-1) + recur_fibo(n-2))


nterms = int(input("How many terms? "))

if nterms <= 0:
   print "Plese enter a positive integer"
else:
   print "Fibonacci sequence:"
   for i in range(nterms):
       print recur_fibo(i)

No comments: