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

  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.

    View all posts

Comments

Leave a Reply

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.