Check if all digits of a number divide it in Python

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this Python program, we will check if all digits of a number divide it or not.

Python Program to check if all digits of a number divide it

def checkDiv(n, digit) : 
return (digit != 0 and n % digit == 0) 
def allDigitsDivide( n) : 
x = n 
while (x > 0) : 
digit = n % 10
if ((checkDivis(n, digit)) == False) : 
return False
x = x // 10
return True
n = 128
if (allDigitsDivide(n)) : 
print("Yes") 
else : 
print("No" ) 

Output: Yes

Leave a Comment

Your email address will not be published. Required fields are marked *