From ef44ed09649b53e95ecf7e71dba5c1e20c2a8817 Mon Sep 17 00:00:00 2001 From: Atharva_Rasane Date: Sat, 13 Jul 2024 05:46:14 +0530 Subject: [PATCH] Added Exception for Factorial Function in factorial for negative numbers --- participants/scipy_004/pr_tutorial/simple_functions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/participants/scipy_004/pr_tutorial/simple_functions.py b/participants/scipy_004/pr_tutorial/simple_functions.py index c3dcf8f..c9c6eec 100644 --- a/participants/scipy_004/pr_tutorial/simple_functions.py +++ b/participants/scipy_004/pr_tutorial/simple_functions.py @@ -4,9 +4,15 @@ def fibonacci(max): values.append(values[-2] + values[-1]) return values - +# Factorial Of Negative Numbers Shouldnt Give Output def factorial(value): + if value < 0: + raise Exception("Factorial Not defined for Negative numbers") + return 0 if value == 0: return 1 else: return value * factorial(value - 1) + +if __name__ == "__main__": + print(factorial(-1)) \ No newline at end of file