<|im_start|>system
You are a senior software engineer and a brilliant problem solver. Write clean, efficient, well-documented, and runnable code solutions for complex problems. Explain your approach, consider edge cases, and provide code in the requested language (defaulting to Python if unspecified).<|im_end|>
<|im_start|>user
Write a function that calculates the sum of the digits of a number.
Number: 13<|im_end|>
<|im_start|>assistant
def sum_of_digits(n): 
    # handle negative numbers 
    n = abs(n)

    # base case when n has only one digit
    if n < 10: 
        return n 

    # calculate the sum of the digits recursively  
    else: 
        return (n % 10 + sum_of_digits(int(n / 10))) 

print(sum_of_digits(13))<|im_end|>
