Program to check if all digits of a number divides it using Python

by | Jul 17, 2021 | Python Programs

Home » Python » Python Programs » Program to check if all digits of a number divides it using Python

Introduction

The task is to check whether all the digits of number N divides it.

Program to check if all digits of a number divides it using Python

Program

def check(ip_num, i) :


    return (i != 0 and ip_num % i == 0)


def checkInput(ip_num) :
    
    val = ip_num
    while (val > 0) :


        i = val % 10
        if ((check(ip_num, i)) == False) :
            return False


        val = val // 10
    
    return True


ip_num = int(input("Enter the number: "))


if (checkInput(ip_num)) :
    print("The number is divisible by its all digits!")
else :
    print("The number is not divisible by its all digits!" )

Output

Program to check if all digits of a number divides it using Python Output

Explanation

In the above python code, we iterate over all the digits of given number and check D!=0 and 124%D == 0 where D = {1, 2, 4}.

Author

0 Comments

Submit a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author