Harshad numbers

Question Q2.7.3

A Harshad number is an integer that is divisible by the sum of its digits (for example, 21 is divisible by $2+1=3$ and so is a Harshad number). Correct the following code which should return True or False if n is a Harshad number or not respectively:

def digit_sum(n):
    """ Find the sum of the digits of integer n. """

    s_digits = list(str(n))
    dsum = 0
    for s_digit in s_digits:
        dsum += int(s_digit)

def is_harshad(n):
    return not n % digit_sum(n)

When run, the function is_harshad raises an error:

>>> is_harshad(21)
TypeError: unsupported operand type(s) for %: 'int' and 'NoneType'

Solution