Numbers with Digit Sum Multiple of 3
Print numbers 1-100 whose digit sum is multiple of 3.
AdvancedPhase 2 - Level 5: Logical Loop CombinationsExample 4 of 12
numbers-with-digit-sum-multiple-of-3.py
1# Print numbers2print("Numbers with digit sum multiple of 3:")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 multiple of 312 if digit_sum % 3 == 0:13 print(num, end=" ")14print()
Output
Numbers with digit sum multiple of 3: 3 6 9 12 15 18 21 ...
What's going on
Calculate digit sum and check divisibility by 3.
Key Concepts:
Extract and sum digits
Check if sum % 3 == 0
Filter 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