From f4c3e5f006b802b6c2dc6945db73e8b628de0470 Mon Sep 17 00:00:00 2001 From: ashuray Date: Wed, 11 Oct 2017 01:19:04 +0530 Subject: [PATCH] Python Program to print factorial of a number --- factorial.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 factorial.py diff --git a/factorial.py b/factorial.py new file mode 100644 index 0000000..a2c79c2 --- /dev/null +++ b/factorial.py @@ -0,0 +1,15 @@ +# Python program to find the factorial of a number + +def factorial(n): + + if n == 0: + return 1 + else: + return n * factorial(n - 1) + + +num = int(input("Enter the number:")) +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +else: + print(factorial(num))