Challenge 1: Find The Factorial
This lesson will test your knowledge of loops.
We'll cover the following
Problem Statement
The task is to print the factorial of a number n
.
The factorial of a number n is the product of all numbers from 1 to n.
factorial (3)= 3 * 2 * 1 factorial(3) = 6
Note: Assume that the negative numbers may be passed in as argument and that the factorial of a negative number should be set as zero.
Input
Integer
Output
Integer
Sample Input
3
Sample Output
6
Coding Exercise
Write your code below. It is recommended that you try solving the exercise yourself before viewing the solution.
Note: There is a
test
function given in the code for testing purposes. Do not modify it.
Good luck! 🤞
Create a free account to access the full course.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy