Learn
All right! Now we’re cooking. Let’s try a factorial problem.
To calculate the factorial of a non-negative integer x
, just multiply all the integers from 1 through x
. For example:
factorial(4)
would equal4 * 3 * 2 * 1
, which is 24.factorial(1)
would equal1
.factorial(3)
would equal3 * 2 * 1
, which is 6.
Instructions
1.
Define a function factorial
that takes an integer x
as input.
Calculate and return the factorial of that number.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.