Program to check if a number is divisible by sum of its digits | Python implementation of above approach ; Converting integer to string ; Initialising sum to 0 ; Traversing through the string ; Converting character to int ; Comparing number and sum ; Driver Code ; passing this number to get result function
def getResult ( n ) : NEW_LINE INDENT st = str ( n ) NEW_LINE sum = 0 NEW_LINE length = len ( st ) NEW_LINE for i in st : NEW_LINE INDENT sum = sum + int ( i ) NEW_LINE DEDENT if ( n % sum == 0 ) : NEW_LINE INDENT return " Yes " NEW_LINE DEDENT else : NEW_LINE INDENT return " No " NEW_LINE DEDENT DEDENT n = 123 NEW_LINE print ( getResult ( n ) ) NEW_LINE