From 4217feaf5b77297daf95f372e140829987be92c9 Mon Sep 17 00:00:00 2001 From: ADITYA KUMAR <65608954+AdityaKumar123-aks@users.noreply.github.com> Date: Fri, 1 Oct 2021 04:25:55 -0700 Subject: [PATCH] factorial.py --- Recursion/Python/factorial.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Recursion/Python/factorial.py diff --git a/Recursion/Python/factorial.py b/Recursion/Python/factorial.py new file mode 100644 index 0000000..cb793f2 --- /dev/null +++ b/Recursion/Python/factorial.py @@ -0,0 +1,14 @@ +def recur_factorial(n): + if n == 1: + return n + else: + return n*recur_factorial(n-1) + +num = 7 + +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + print("The factorial of", num, "is", recur_factorial(num))