Generate a Python code snippet for calculating the factorial of a number.