Loading...
Loading...
Loading...
The number of ways to arrange n parcels in a row is n factorial: n * (n - 1) * ... * 1, with 0 factorial equal to 1. Write a recursive function factorial(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.
The base case is n being 0 or 1, which returns 1.
Otherwise the answer is 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