def sum_of_digits(num):
    """Function to calculate sum of digits of an integer"""
    if num == 0:
        return 0
    else:
        ans = 0
        while num != 0:
            rem = num % 10
            ans = ans + rem
            num = num // 10
        return ans