From 490126b31a4630f020e736c0b113c21c4cf751bf Mon Sep 17 00:00:00 2001 From: Vibhanshu Singh <135852806+singhvibhanshu@users.noreply.github.com> Date: Sat, 19 Oct 2024 12:27:07 +0530 Subject: [PATCH] Create factorial.py Fixes #12142 --- recursion/factorial.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 recursion/factorial.py diff --git a/recursion/factorial.py b/recursion/factorial.py new file mode 100644 index 000000000000..51d38469a6ca --- /dev/null +++ b/recursion/factorial.py @@ -0,0 +1,7 @@ +def factorial(n): + if n == 0 or n == 1: + return 1 + else: + return n * factorial(n - 1) + +print(factorial(5)) # Example