Advertisement
Guest User

Untitled

a guest
Sep 26th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. # Python program to display the Fibonacci sequence up to n-th term using recursive functions
  2. import time
  3.  
  4. def recur_fibo(n):
  5. """Recursive function to
  6. print Fibonacci sequence"""
  7. if n <= 1:
  8. return n
  9. else:
  10. return(recur_fibo(n-1) + recur_fibo(n-2))
  11.  
  12. nterms = 10
  13.  
  14. if nterms <= 0:
  15. print("Plese enter a positive integer")
  16. else:
  17. start = time.clock()
  18. print("Fibonacci sequence:")
  19. for i in range(nterms):
  20. print(recur_fibo(i))
  21. print time.clock() - start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement