<|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
Create a function in Python to calculate the factorial of a number.
<|im_end|>
<|im_start|>assistant
def factorial(n):
    """This function returns the factorial of a given integer"""
    if n == 0:
        return 1
    else: 
        return n * factorial(n-1)<|im_end|>
