Challenge 1: Find The Factorial

This lesson will test your knowledge of loops.

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(n)=n(n1)(n2)...1factorial(n)=n * (n-1) * (n-2) * ... * 1

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.

By signing up, you agree to Educative's Terms of Service and Privacy Policy