Python Program - Find Factorial of Number Using Recursion
here's a Python program that finds the factorial of a given number using recursion:
referfigi:ot tidea.comdef factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
n = int(input("Enter a number: "))
print("Factorial of", n, "is", factorial(n))
In this program, we define a function called factorial() that takes a single argument n. If n is 0, then we return 1 (since the factorial of 0 is 1). Otherwise, we recursively call factorial(n-1) and multiply the result by n to get the factorial of n.
We then use the input() function to get a number from the user, and store it in the variable n.
We then call the factorial() function with n as its argument, and use the print() function to print out the result.
