First Factorial
Factorial of a number in Python
Have the function FirstFactorial(num) take the num parameter being passed and return the factorial of it. For example: if num = 4, then your program should return (4 * 3 * 2 * 1) = 24.
For the test cases, the range will be between 1 and 18 and the input will always be an integer.
Examples
Input: 4
Output: 24
Input: 8
Output: 40320
Code:
Method1:
#Using Recursion def FirstFactorial(num): # code goes here if num==1: return 1 else: return num * FirstFactorial(num-1) # keep this function call here print(FirstFactorial(input()))
Method2:
def FirstFactorial(num): # code goes here f=1 for i in range(1,num+1): f=f*i return f # keep this function call here print(FirstFactorial(input()))