Print Diamond Pattern
Print diamond pattern with stars.
IntermediatePhase 2 - Level 4: Pattern PrintingExample 8 of 13
print-diamond-pattern.py
1# Take n2n = int(input("Enter number of rows: "))34# Upper half5for i in range(1, n + 1):6 print(" " * (n - i), end="")7 print("*" * (2 * i - 1))89# Lower half10for i in range(n - 1, 0, -1):11 print(" " * (n - i), end="")12 print("*" * (2 * i - 1))
Output
Enter number of rows: 4 * *** ***** ******* ***** *** *
What's going on
Print upper pyramid then inverted lower pyramid.
Key Concepts:
Upper: increasing stars
Lower: decreasing stars
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