Sum of Squares of Even Numbers
Sum squares of even numbers from 1 to n.
AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 11 of 12
sum-of-squares-of-even-numbers.py
1# Take n2n = int(input("Enter n: "))34# Sum squares of evens5sum_sq_even = 06for i in range(2, n + 1, 2):7 sum_sq_even += i * i89print(f"Sum of squares of evens: {sum_sq_even}")
Output
Enter n: 10 Sum of squares of evens: 220
What's going on
Filter even numbers and sum their squares.
Key Concepts:
Loop with step 2 for evens
Square each even number
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