From de64d33148ed016957f2502b828261d0843a074f Mon Sep 17 00:00:00 2001 From: Guest Date: Thu, 7 Oct 2021 19:26:00 +0530 Subject: [PATCH] Added factorial program in python folder --- python/algorithms/fact.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 python/algorithms/fact.py diff --git a/python/algorithms/fact.py b/python/algorithms/fact.py new file mode 100644 index 000000000..db3a9978d --- /dev/null +++ b/python/algorithms/fact.py @@ -0,0 +1,15 @@ +def factorial(n): + if n < 0: + return 0 + elif n == 0 or n == 1: + return 1 + else: + fact = 1 + while(n > 1): + fact *= n + n -= 1 + return fact + +my_num = 5; +print("Factorial of",my_num,"is", +factorial(my_num))