Factorial of Each Number 1-N
Print factorial of each number from 1 to n.
AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 8 of 12
factorial-of-each-number-1-n.py
1# Take n2n = int(input("Enter n: "))34# Print factorials5for i in range(1, n + 1):6 fact = 17 for j in range(1, i + 1):8 fact *= j9 print(f"{i}! = {fact}")
Output
Enter n: 5 1! = 1 2! = 2 3! = 6 4! = 24 5! = 120
What's going on
Calculate factorial for each number.
Key Concepts:
Outer loop: numbers 1 to n
Inner loop: calculate factorial
Print each factorial
🔗Related Content
- 📖
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- 📝
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- 💻
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum