aboutsummaryrefslogtreecommitdiff
path: root/entries/jjhickmon
diff options
context:
space:
mode:
authorJavon Hickmon2022-12-19 07:09:10 +0000
committerGitHub2022-12-19 07:09:10 +0000
commit0f859e133c4c9d6c071f15b54d1b03e7b68f0b21 (patch)
treecad4ee8defe6ce8a302d51f9acfea47000519123 /entries/jjhickmon
parent77e827e1ad5e4598811335e7f0c9bfeb20a425c4 (diff)
Added Javon's fibonacci function
Diffstat (limited to 'entries/jjhickmon')
-rw-r--r--entries/jjhickmon/fibonacci.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/entries/jjhickmon/fibonacci.py b/entries/jjhickmon/fibonacci.py
new file mode 100644
index 0000000..7e9f5f6
--- /dev/null
+++ b/entries/jjhickmon/fibonacci.py
@@ -0,0 +1,14 @@
+def fib(index):
+ if (index < 0):
+ raise IndexError("Error: index must be >= 0")
+
+ prev = 1
+ curr = 1
+ for _ in range(index - 1):
+ temp = curr
+ curr += prev
+ prev = temp
+ return curr
+
+if __name__ == "__main__":
+ print(fib(5))