Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import *
- def fibonacci_term(n):
- if n==1:
- return 0
- elif n==2:
- return 1
- else:
- return fibonacci_term(n-1)+fibonacci_term(n-2)
- def previousfibonacci(n):
- if n == 0:
- return float(1)
- else:
- a = n/((1 + sqrt(5))/2.0)
- return round(a)
- def fibonacci(start_term,numofterm):
- if start_term<0:
- print("Incorrect input")
- else:
- print float(fibonacci_term(start_term))
- fiblist=[]
- n = numofterm
- fiblist.append(float(fibonacci_term(start_term)))
- temp = fibonacci_term(start_term)
- while n > 1 :
- temp2 = temp + previousfibonacci(temp)
- print temp2
- fiblist.append(temp2)
- temp = temp2
- n -= 1
- else:
- print fiblist
- fibonacci(2,20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement