11Factorial

    Easyloopsmath

    Write factorial(n) that returns n! = 1 × 2 × 3 × … × n.

    By definition factorial(0) is 1.

    Examples

    Example 1
    >>> factorial(5)
    120
    Example 2
    >>> factorial(0)
    1

    Good to know

    • n is never negative.

    Run examples checks the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write factorial in the editor, then run the examples. Use print() freely: its output is shown for each test.