Run Details #674

Score

0

Stored run score 40 recalculated to 0 after question exclusions.
Correct (≥100)

0/1

Incorrect (<100)

1

Median Time

4855.0ms

Tokens Used

454

Cost

243µ$

Run Date: 2026-03-02 23:13:55
Coding question results (1)
0302_python_gcd:0 Incorrect
Score: 40 • 4855ms • 454 tokens • 243µ$
Question: Write Python 3.12 code only. Define exactly one function named gcd_checked(a, b). It must return the greatest common divisor of two integers. Raise TypeError if either argument is not an int. Raise ValueError if either argument is <= 0. Do not use any imports (no numpy, requests, or other libraries). Sandbox note: dunder attribute access is blocked (for example, type(x).__name__). Avoid names/attributes starting with '__'. Expected output format: - Return exactly one fenced Markdown code block starting with ```python and ending with ```. - Put only valid Python code inside that block (no prose before/after). - Use 4 spaces for indentation (not tabs). - Do not return JSON and do not wrap code in a "function" key. Sample input/output behavior: - gcd_checked(54, 24) -> 6 Task: Write a Python 3.12 function that calculates GCD (greatest common denominator) and raises exceptions for invalid input.
Submitted code
def gcd_checked(a: int, b: int) -> int:
    """
    Calculates the greatest common divisor of two integers.

    Args:
        a (int): The first integer.
        b (int): The second integer.

    Returns:
        int: The greatest common divisor of a and b.
    """

    # Handle invalid input types
    if not isinstance(a, int) or not isinstance(b, int):
        raise TypeError("Arguments must be integers.")
    elif a <= 0 or b <= 0:
        raise ValueError("Arguments can't be non-positive.")

    # Initialize greatest common divisor to the larger of the two numbers
    gcd = max(a, b)

    # Iterate until the gcd is divisible by both numbers without remainder
    while gcd % a == 0 and gcd % b == 0:
        gcd += 1

    return gcd
Test case results
# Status Args Expected Actual Error
0 Fail [54, 24] 6 54 -
1 Fail [48, 18] 6 48 -
2 Fail [17, 13] 1 17 -
3 Fail [100, 10] 10 101 -
4 Fail [270, 192] 6 270 -
5 Fail [1, 1] 1 - Execution timed out
6 Pass [0, 5] ValueError ValueError -
7 Pass [-4, 6] ValueError ValueError -
8 Pass [3.5, 2] TypeError TypeError -
9 Pass ['9', 3] TypeError TypeError -