Number Pyramid
Print number pyramid pattern.
IntermediatePhase 2 - Level 4: Pattern PrintingExample 9 of 13
number-pyramid.py
1# Take n2n = int(input("Enter number of rows: "))34# Print number pyramid5for i in range(1, n + 1):6 # Spaces7 print(" " * (n - i), end="")8 # Numbers9 for j in range(1, i + 1):10 print(j, end="")11 # Reverse numbers12 for j in range(i - 1, 0, -1):13 print(j, end="")14 print()
Output
Enter number of rows: 4 1 121 12321 1234321
What's going on
Print numbers increasing then decreasing.
Key Concepts:
Print spaces for alignment
Print 1 to i
Print i-1 down to 1
Symmetric pattern
🔗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