Print Pyramid Pattern
Print pyramid pattern with stars.
IntermediatePhase 2 - Level 4: Pattern PrintingExample 3 of 13
print-pyramid-pattern.py
1# Take n2n = int(input("Enter number of rows: "))34# Print pyramid5for i in range(1, n + 1):6 # Print spaces7 for j in range(n - i):8 print(" ", end="")9 # Print stars10 for j in range(2 * i - 1):11 print("*", end="")12 print()
Output
Enter number of rows: 5
*
***
*****
*******
*********What's going on
Print spaces before stars for alignment.
Key Concepts:
Spaces: n - i
Stars: 2 * i - 1 (odd numbers)
Center alignment
🔗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