diff --git a/fibo.py b/fibo.py deleted file mode 100644 index 4361cce..0000000 --- a/fibo.py +++ /dev/null @@ -1,13 +0,0 @@ -def fib(n): # write Fibonacci series up to n - a, b = 0, 1 - while b < n: - print b, - a, b = b, a+b - -def fib2(n): # return Fibonacci series up to n - result = [] - a, b = 0, 1 - while b < n: - result.append(b) - a, b = b, a+b - return result diff --git a/fibonacci.py b/fibonacci.py new file mode 100644 index 0000000..7087a04 --- /dev/null +++ b/fibonacci.py @@ -0,0 +1,12 @@ +FibArray = [0,1] +def fibonacci(n): + if n<=0: + print("Incorrect input") + elif n<=len(FibArray): + return FibArray[n-1] + else: + temp_fib = fibonacci(n-1)+fibonacci(n-2) + FibArray.append(temp_fib) + return temp_fib +x=int(input()) +print(fibonacci(x)) \ No newline at end of file