Loops and patterns · Python exercise
Compute n! with a loop, including the special case 0! = 1.
Read a non-negative integer n and print n! (the product of every integer from 1 to n). By definition, 0! is 1.
Example 1
Input
5
Output
120
Example 2
Input
0
Output
1
The empty product is 1.
How testing works
Your code runs once per test case with that case's standard input. Output is compared after normalising trailing spaces and blank lines at the end. Use input() without a prompt when the exercise expects clean output.
Loading editor…
Press Run tests to execute your code against every input case. Python runs in a Web Worker in your browser.