From cc3c430e8b4fe9dd61941e9ce47a62e7dd093793 Mon Sep 17 00:00:00 2001 From: prithviokade Date: Wed, 8 Sep 2021 13:51:31 -0400 Subject: [PATCH 1/2] Adding case for negative inputs --- fib.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fib.py b/fib.py index 50722c2..8c8f930 100644 --- a/fib.py +++ b/fib.py @@ -6,6 +6,8 @@ Negative numbers should return None """ def fibonacci(position): + if (position < 0): + return None if(position == 1 or position == 2): return 1 return fibonacci(position - 1) + fibonacci(position - 2) From 926f30af508ee988e02b1de5598778663a0ba825 Mon Sep 17 00:00:00 2001 From: Michael Aspinwall Date: Wed, 8 Sep 2021 13:51:34 -0400 Subject: [PATCH 2/2] Create a zero base case --- fib.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fib.py b/fib.py index 50722c2..6c0d083 100644 --- a/fib.py +++ b/fib.py @@ -6,6 +6,8 @@ Negative numbers should return None """ def fibonacci(position): + if(position == 0): + return 0 if(position == 1 or position == 2): return 1 return fibonacci(position - 1) + fibonacci(position - 2)