Sum of Squares Up to N
Calculate sum of squares from 1² to n².
BeginnerPhase 2 - Level 1: Basic LoopingExample 13 of 14
sum-of-squares-up-to-n.py
1# Take n as input2n = int(input("Enter n: "))34# Calculate sum of squares5sum_squares = 06for i in range(1, n + 1):7 sum_squares += i * i89print(f"Sum of squares: {sum_squares}")
Output
Enter n: 5 Sum of squares: 55
What's going on
Square each number and add to sum.
Key Concepts:
Loop from 1 to n
Calculate i * i for each
Accumulate sum
🔗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