diff --git a/fib.py b/fib.py index 5cb1b2c..72bbdff 100644 --- a/fib.py +++ b/fib.py @@ -4,7 +4,13 @@ def fib_loop(n): It uses for loop to calculate it. ''' - + fib = [1,1] + + for i in range(n-2): + x= fib[i+1]+fib[i] + fib.append(x) + + return fib[n-1] def fib_recursion(n): ''' @@ -12,6 +18,19 @@ def fib_recursion(n): It uses for loop to calculate it. ''' + fib1=1 + fib2=1 + + for i in range(n-2): + fib3 = fib2 + fib1 + fib1 = fib2 + fib2 = fib3 + + return fib3 + +print(fib_loop(8)) +print(fib_recursion(13)) + def fib_generator(n): ''' @@ -21,3 +40,4 @@ def fib_generator(n): print(fib_loop(8)) print(fib_recursion(13)) print([i for i in fib_generator(14)]) +