All problems
Factorial for Counting Outcomes
Problem
Compute n! iteratively as 1 * 2 * ... * n.
Return 1 when n = 0, since the empty product is 1, and 0 for negative n.
Hint
The empty product is 1, and factorials are never defined for negative integers here.
Test cases
case 1
in: [5]
expected: 120
case 2
in: [0]
expected: 1
case 3
in: [1]
expected: 1
case 4
in: [10]
expected: 3628800
case 5
in: [-3]
expected: 0
Starter codePython
def factorial(n):
# Your code here
pass5 test cases · run your code against them in the editor