Loading...
Loading...
Loading...
Write a recursive function factorial(n) that returns n! (the product of 1 to n, with 0! = 1). Read n and print the result.
Example
Input
5
Output
120
5 * 4 * 3 * 2 * 1.
Try the problem first. Open one hint at a time.
Treat 0 and 1 as the base case.
Return n times the factorial of n - 1.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor