Answer to Question #256409 in Python for rasi

Question #256409

Find the output based on input, the sum of digits of output is equal to input and divisible by input.- Link

 


1
Expert's answer
2021-10-27T00:25:36-0400
# Python 3 implementation of above approach
 
# Function to check if the given number 
# is divisible by sum of its digits

def isDivisible(n):

 

    temp = n

 

    # Find sum of digits


    sum = 0;


    while (n): 


     

        k = n % 10;


        sum += k;


        n /= 10;


     

    # check if sum of digits divides n


    if (temp % sum == 0):


        return "YES";

 

    return "NO";

 
# Driver Code

n = 123;

 

print(isDivisible(n));

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS