Recursive Factorial
Easy
14
88.3% Acceptance
Welcome to the Factorial Calculation Lab! In this lab, you will implement a function named factorial()
in Python. Your task is to calculate the factorial of a given positive integer using a recursive approach.
The factorial of a number n
(denoted as n!
) is the product of all positive integers from 1 to n
. For example, 4! = 4 x 3 x 2 x 1 = 24
.
Function Requirements:
- The function should be named
factorial
. - It must use recursion to calculate the factorial.
- The function should take a single integer argument and return the factorial of that number.
Examples:
-
Input:
5
Expected Output:120
Explanation:5! = 5 x 4 x 3 x 2 x 1 = 120
-
Input:
3
Expected Output:6
Explanation:3! = 3 x 2 x 1 = 6
Remember to test your function with various inputs, including the numbers provided in the challenges. Good luck!