From 63cdb351737ee8f1b886de10b0bfc0dd02058f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alim=20Kerem=20Erdo=C4=9Fmu=C5=9F?= Date: Fri, 7 Jan 2022 15:59:22 +0300 Subject: [PATCH] chore(Python): rename n-th_fibonacci_number.py to nth_fibonacci_number.py (#664) --- algorithms/Python/README.md | 2 +- .../Python/recursion/n-th_fibonacci_number.py | 18 ---------------- .../Python/recursion/nth_fibonacci_number.py | 21 +++++++++++++++++++ 3 files changed, 22 insertions(+), 19 deletions(-) delete mode 100644 algorithms/Python/recursion/n-th_fibonacci_number.py create mode 100644 algorithms/Python/recursion/nth_fibonacci_number.py diff --git a/algorithms/Python/README.md b/algorithms/Python/README.md index c2575be5..a307dd3a 100644 --- a/algorithms/Python/README.md +++ b/algorithms/Python/README.md @@ -19,7 +19,7 @@ ## Recursion - [Factorial](recursion/factorial.py) -- [n-th Fibonacci number](recursion/n-th_fibonacci_number.py) +- [n-th Fibonacci number](recursion/nth_fibonacci_number.py) - [Recursive Insertion Sort](recursion/recursive_insertion_sort.py) ## Scheduling diff --git a/algorithms/Python/recursion/n-th_fibonacci_number.py b/algorithms/Python/recursion/n-th_fibonacci_number.py deleted file mode 100644 index bb367a2b..00000000 --- a/algorithms/Python/recursion/n-th_fibonacci_number.py +++ /dev/null @@ -1,18 +0,0 @@ -# Function for nth fibonacci number - Using recursion -# Taking 1st two fibonacci numbers as 0 and 1 - -FibArray = [1] -def fibonacci(n): - if n<0: - print("Incorrect input") - if n == 0: - return 0 - elif n<= len(FibArray): - return FibArray[n-1] - else: - temp_fib = fibonacci(n-1)+fibonacci(n-2) - FibArray.append(temp_fib) - return temp_fib - -# Driver Program -print(fibonacci(100)) diff --git a/algorithms/Python/recursion/nth_fibonacci_number.py b/algorithms/Python/recursion/nth_fibonacci_number.py new file mode 100644 index 00000000..1dffd103 --- /dev/null +++ b/algorithms/Python/recursion/nth_fibonacci_number.py @@ -0,0 +1,21 @@ +""" +Function for nth fibonacci number - Using recursion +Taking 1st two fibonacci numbers as 0 and 1 +""" + +FibArray = [1] +def fibonacci(n_val): + """Fibonacci Number Main Function""" + if n_val < 0: + sol = "Incorrect input" + elif n_val == 0: + sol = 0 + elif n_val <= len(FibArray): + sol = FibArray[n_val-1] + else: + temp_fib = fibonacci(n_val-1)+fibonacci(n_val-2) + FibArray.append(temp_fib) + sol = temp_fib + return sol +# Driver Program +print(fibonacci(100))