Factorial Calculation

Tags: Loop, Math

Write a Python program that prints the factorial of a number. The number will be a single integer input from the user.

Example 1:

Input: 4
Output: 24

Example 2:

Input: 6
Output: 720

You can calculate the factorial of a number n as the product of all positive integers less than or equal to n. Consider using a loop.

n = int(input())
fact = 1
for i in range(1, n+1):
fact *= i
print(fact)

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!