#Fibonacci Number without recursion

def fib1(n):
    f0 =0
    f1 =1
    f=0
    if n == 0 :
	return 0
    elif n == 1:
	return 1
    while n>1:
	f = f1 +f0
	f0 = f1
	f1 = f
	n=n-1
    return f
Published in: Python
Download

Related snippets