This Python program reads an integer from the user and displays the digits that are divisible by 2 or 3.
Each digit is checked individually, and only those divisible by 2 or 3 are printed.
# Read input from user
num = input("Enter an integer: ")
# Display digits divisible by 2 or 3
print("Digits divisible by 2 or 3:")
for digit in num:
if digit.isdigit():
d = int(digit)
if d % 2 == 0 or d % 3 == 0:
print(d)
Input: 1234567890
Digits divisible by 2 or 3:
2
3
4
6
8
9
0
- The number is read as a string to allow digit-by-digit inspection
- Each character is checked to ensure it’s a digit
- If the digit is divisible by 2 or 3, it is printed