Logic Building
# Take n
n = int(input("Enter n: "))
# Print factorials
for i in range(1, n + 1):
fact = 1
for j in range(1, i + 1):
fact *= j
print(f"{i}! = {fact}")Output
Enter n: 5 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120
Calculate factorial for each number.
Key Concepts:
- Outer loop: numbers 1 to n
- Inner loop: calculate factorial
- Print each factorial