Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python program to display the Fibonacci sequence up to n-th term using recursive functions
- import time
- def recur_fibo(n):
- """Recursive function to
- print Fibonacci sequence"""
- if n <= 1:
- return n
- else:
- return(recur_fibo(n-1) + recur_fibo(n-2))
- nterms = 10
- if nterms <= 0:
- print("Plese enter a positive integer")
- else:
- start = time.clock()
- print("Fibonacci sequence:")
- for i in range(nterms):
- print(recur_fibo(i))
- print time.clock() - start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement