Harshad Numbers
Find Harshad numbers (divisible by sum of digits).
AdvancedPhase 6 - Category 1: Number LogicExample 10 of 10
harshad-numbers.py
1# Find Harshad numbers2print("Harshad numbers 1-100:")34for num in range(1, 101):5 digit_sum = sum(int(d) for d in str(num))6 if digit_sum > 0 and num % digit_sum == 0:7 print(num, end=" ")8print()
Output
Harshad numbers 1-100: 1 2 3 4 5 6 7 8 9 10 12 18 20 21 ...
What's going on
Check if number divisible by digit sum.
Key Concepts:
Calculate sum of digits
Check if num % digit_sum == 0
Filter numbers
🔗Related Content
- 📖
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- 📝
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- 💻
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum