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))