Numbers with Even Digit Sum
Print numbers 1-100 whose digit sum is even.
AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 1 of 12
numbers-with-even-digit-sum.py
1# Print numbers with even digit sum2print("Numbers 1-100 with even digit sum:")3for num in range(1, 101):4 # Calculate digit sum5 digit_sum = 06 temp = num7 while temp > 0:8 digit_sum += temp % 109 temp //= 101011 # Check if sum is even12 if digit_sum % 2 == 0:13 print(num, end=" ")14print()
Output
Numbers 1-100 with even digit sum: 2 4 6 8 11 13 15 17 19 20 ...
What's going on
Calculate digit sum and check if even.
Key Concepts:
Extract digits and sum
Check if sum % 2 == 0
Filter numbers meeting condition
🔗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