Finding Factorial Using Math Module

Write a Python program that uses the math module to find the factorial of a user input number. Return the factorial.

Example 1:

Input: 5
Output: 120

Example 2:

Input: 7
Output: 5040

Use the factorial() function from the math module.

import math

def factorial(num):
    return math.factorial(num)

# Test the function
print(factorial(5))  # Output: 120
print(factorial(7))  # Output: 5040

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!