Recursive Factorial
Completed
Write a recursive fact(n) and print fact(n).
Input
One integer 0–50.
Output
n!
Example
Input
5
Output
120
Editor
Python
Hints
Every recursion needs a base case that stops it.
n! = n × (n−1)!
Solution explanation
A recursive function solves a smaller version of the same problem until it reaches the base case.
Show solution
def fact(n):
if n <= 1:
return 1
return n * fact(n - 1)
print(fact(int(input())))