From 59bff205b510ee72a76f3d61a10490b1b5228303 Mon Sep 17 00:00:00 2001 From: Pratik Bambulkar <72552513+Pratik180198@users.noreply.github.com> Date: Fri, 23 Oct 2020 12:59:39 +0530 Subject: [PATCH] Update factorial.py As I saw there was not a factorial program so I had added the factorial program by solving it with two methods using FOR LOOP and RECURSIVE METHOD. --- factorial.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/factorial.py b/factorial.py index e69de29..c3cdd45 100644 --- a/factorial.py +++ b/factorial.py @@ -0,0 +1,16 @@ +num1=input("Enter number: ") +try: + num=int(num1) + fact=1 + for i in range(1,num+1): #Using For Loop + fact=fact*i + print("Factorial of {} is {}".format(num,fact)) #For Loop Answer + + def factorial(num): #Using Recursive Method + if num == 0 or num ==1: + return 1 + else: + return num * factorial(num-1) + print(f"Factorial of {num} is {factorial(num)}") #Recursive Method Answer +except: + print("Please enter only integer")