```python
def code_valid(code: str, length: int) -> bool:
    if length <= 0:
        raise ValueError("Length must be greater than zero")
    if not code.isupper() or not code.isdigit():
        return False
    return len(code) == length
```