Python Program for Check if all Digits of a Number Divide It (original) (raw)

Last Updated : 31 Oct, 2025

Given a number N, the task is to check whether all digits of the number divide it completely or not. In simple terms, every non-zero digit in the number should divide N evenly. **For example:

**Input: 128
**Output: Yes -> (128 % 1 == 0, 128 % 2 == 0, 128 % 8 == 0)

**Input: 130
**Output: No -> (130 % 3 != 0)

Let’s explore different ways to solve this efficiently in Python.

Using all() with String Iteration

It converts the number into a string, checks each digit (ignoring zeros), and uses all() to verify that every digit divides the number evenly.

python `

n = 128 if all(int(d) != 0 and n % int(d) == 0 for d in str(n)): print("Yes") else: print("No")

`

**Explanation:

Using Mathematical Operations

This method extracts each digit mathematically using modulus and division, checking divisibility as it goes.

Python `

n = 128 temp = n flag = True

while temp > 0: digit = temp % 10 if digit == 0 or n % digit != 0: flag = False break temp //= 10

if flag: print("Yes") else: print("No")

`

**Explanation:

Using map() and list() Conversion

This method converts digits to a list of integers, then iterates through each digit to check divisibility.

Python `

n = 128 digits = list(map(int, str(n))) count = 0

for d in digits: if d != 0 and n % d == 0: count += 1

if count == len(digits): print("Yes") else: print("No")

`

**Explanation:

Using List Comprehension and sum()

This approach checks divisibility using list comprehension and compares how many digits divide the number.

Python `

n = 128 digits = [int(d) for d in str(n)] res = [d for d in digits if d != 0 and n % d == 0]

if len(res) == len(digits): print("Yes") else: print("No")

`

**Explanation:

Please refer complete article on Check if all digits of a number divide it for more details!