Print Hollow Square
Print hollow square pattern.
IntermediatePhase 2 - Level 4: Pattern PrintingExample 7 of 13
print-hollow-square.py
1# Take n2n = int(input("Enter size: "))34# Print hollow square5for i in range(n):6 for j in range(n):7 if i == 0 or i == n-1 or j == 0 or j == n-1:8 print("*", end="")9 else:10 print(" ", end="")11 print()
Output
Enter size: 5 ***** * * * * * * *****
What's going on
Print stars only on borders.
Key Concepts:
First row, last row: all stars
First column, last column: stars
Middle: spaces
🔗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