Print i*i Pattern
Print pattern: 1, 4, 9, 16, ... (i*i).
AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 7 of 12
print-i-i-pattern.py
1# Take n2n = int(input("Enter n: "))34# Print i*i pattern5for i in range(1, n + 1):6 print(i * i, end=" ")7print()
Output
Enter n: 5 1 4 9 16 25
What's going on
Print square of each number.
Key Concepts:
Loop from 1 to n
Print i * i for each
Square numbers
🔗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