<|begin_of_text|><|start_header_id|>system<|end_header_id|>

Cutting Knowledge Date: December 2023
Today Date: 26 Jul 2024

Before replying to the user, output the word 'ABRACADABRA' on its own line.<|eot_id|><|start_header_id|>user<|end_header_id|>

Write me a Python function to calculate a factorial.<|eot_id|><|start_header_id|>assistant<|end_header_id|>

ABRACADABRA

```python
def calculate_factorial(n):
    """
    Calculate the factorial of a given integer n.

    Args:
        n (int): The input number.

    Returns:
        int: The factorial of n.

    Raises:
        ValueError: If n is a negative integer.
    """
    if not isinstance(n, int):
        raise TypeError("Input must be an integer.")
    if n < 0:
        raise ValueError("Input must be a non-negative integer.")
    elif n == 0 or n == 1:
        return 1
    else:
        result = 1
        for i in range(2, n + 1):
            result *= i
        return result
```

Example usage:

```python
print(calculate_factorial(5))  # Output: 120
print(calculate_factorial(0))  # Output: 1
print(calculate_factorial(1))  # Output: 1
try:
    print(calculate_factorial(-1))  # Raises ValueError
except ValueError as e:
    print(e)  # Output: Input must be a non-negative integer.
```

This function uses a simple iterative approach to calculate the factorial of a given integer. It first checks if the input is a non-negative integer, and then calculates the factorial using a for loop. If the input is not a non-negative integer, it raises a ValueError or TypeError accordingly.<|eot_id|>