Run Details #636

Score

100

Correct (≥100)

1/1

Incorrect (<100)

0

Median Time

13036.0ms

Tokens Used

495

Cost

652µ$

Run Date: 2026-03-02 20:43:55
Coding question results (1)
0303_python_letter_count:0 Correct
Score: 100 • 13036ms • 495 tokens • 652µ$
Question: Write Python 3.12 code only. Define exactly one function named count_target_letter(text, target). Return how many times the target letter appears in the string. Count should be case-insensitive. Raise TypeError for non-string input, and raise ValueError if target is not exactly one character. 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: - count_target_letter("Mississippi", "s") -> 4 Task: Write a Python 3.12 function for 'how many times does the target letter appear in a string'.
Submitted code
def count_target_letter(text, target):
    """
    Count how many times the target letter appears in the string.
    
    Args:
        text (str): The input string to search in.
        target (str): A single character to search for.
    
    Returns:
        int: The number of times the target letter appears in the string.
    
    Raises:
        TypeError: If `text` is not a string.
        ValueError: If `target` is not exactly one character.
    """
    if not isinstance(text, str):
        raise TypeError("Input 'text' must be a string")
    if len(target) != 1:
        raise ValueError("Target must be exactly one character")

    # Convert both text and target to lowercase for case-insensitive comparison
    text = text.lower()
    target = target.lower()

    # Use list comprehension to create a list of indices where target appears
    indices = [i for i, char in enumerate(text) if char == target]

    # Return the count of indices (which is the number of times target appears)
    return len(indices)

# Example usage:
print(count_target_letter("Mississippi", "s"))  # Output: 4
Test case results
# Status Args Expected Actual Error
0 Pass ['banana', 'a'] 3 3 -
1 Pass ['Mississippi', 's'] 4 4 -
2 Pass ['Hello', 'l'] 2 2 -
3 Pass ['Abracadabra', 'a'] 5 5 -
4 Pass ['CaseSensitive', 'c'] 1 1 -
5 Pass ['', 'x'] 0 0 -
6 Pass ['aaaa', 'a'] 4 4 -
7 Pass ['letter', 'tt'] ValueError ValueError -
8 Pass [42, 'a'] TypeError TypeError -
9 Pass ['abc', 1] TypeError TypeError -