Print Squares from 1 to N
Print square of each number from 1 to n.
IntermediatePhase 2 - Level 3: Mathematical & Logical PatternsExample 1 of 13
print-squares-from-1-to-n.py
1# Take n2n = int(input("Enter n: "))34# Print squares5for i in range(1, n + 1):6 print(f"{i}² = {i * i}")
Output
Enter n: 5 1² = 1 2² = 4 3² = 9 4² = 16 5² = 25
What's going on
Calculate and print square of each number.
Key Concepts:
Loop from 1 to n
Calculate i * i for each
Print formatted output
🔗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