def factorial(n):
if n == 1:
return 1
else:
return n * factorial(n - 1)
# Test the function
print(factorial(5))
120
factorial()
` function calculates the factorial of a given number using recursion. The base case is when `n == 1
`, which means that the function returns `1
` when `n
` is `1
`. n
`, the function calls itself with `n - 1
` as the argument, and multiplies the result by `n
`. The recursion stops when `n
` reaches `1
`, and the final result is returned to the caller.