This Python program reads a list of integers from the user.
It calculates the digit sum of each number and prints only those whose digit sum is divisible by both r and j.
# Read input numbers and divisors
numbers = list(map(int, input("Enter numbers separated by space: ").split()))
r = int(input("Enter value for r: "))
j = int(input("Enter value for j: "))
# Helper function to compute digit sum
def digit_sum(n):
return sum(int(d) for d in str(abs(n)))
# Filter and print valid numbers
print("\n--- Valid Numbers ---")
for num in numbers:
s = digit_sum(num)
if s % r == 0 and s % j == 0:
print(f"{num} (Digit sum: {s})")
Enter numbers separated by space: 12 45 81 33 99
Enter value for r: 3
Enter value for j: 9
--- Valid Numbers ---
81 (Digit sum: 9)
99 (Digit sum: 18)
- The user inputs a list of integers and two divisors r and j
- The program calculates the digit sum of each number using digit_sum()
- If the digit sum is divisible by both r and j, the number is printed
- The result includes the original number and its digit sum