This Python program checks all numbers from 1000 to 1100.
For each number, it calculates the sum of its digits and prints the number if it is divisible by that sum.
# Helper function to calculate digit sum
def digit_sum(n):
return sum(int(d) for d in str(n))
# Check numbers from 1000 to 1100
print("--- Valid Numbers ---")
for num in range(1000, 1101):
s = digit_sum(num)
if num % s == 0:
print(f"{num} (Digit sum: {s})")
--- Valid Numbers ---
1008 (Digit sum: 9)
1012 (Digit sum: 4)
1016 (Digit sum: 8)
1026 (Digit sum: 9)
1035 (Digit sum: 9)
1040 (Digit sum: 5)
1080 (Digit sum: 9)
1089 (Digit sum: 18)
1100 (Digit sum: 2)
- The program loops through numbers from 1000 to 1100
- For each number, it calculates the digit sum using digit_sum()
- If the number is divisible by its digit sum, it is printed
- The output includes both the number and its digit sum for clarity