From 597dfb83834aa59c60e92d687a068a7153eaa780 Mon Sep 17 00:00:00 2001 From: Mohit5700 <72152449+Mohit5700@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:33:15 +0530 Subject: [PATCH] Python Program for factorial of a number Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720. --- factorial | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 factorial diff --git a/factorial b/factorial new file mode 100644 index 0000000..5aaf12c --- /dev/null +++ b/factorial @@ -0,0 +1,16 @@ +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 + +# Driver Code +num = 5; +print("Factorial of",num,"is", +factorial(num))