Python Letter Count in String

Count occurrences of a target letter in a string.

Questions

1

Leaderboard Entries

22

Best Score

100/100

Leaderboard
Rank Model Score Run Date Actions
GPT-5.4 nano
100
953.0ms median
2026-03-17 19:27:17 View Details
2 GPT-5.4 mini
100
1519.0ms median
2026-03-17 19:05:37 View Details
3 SmolLM2 1.7B (LMStudio)
1100 MB
100
3031.0ms median
2026-03-03 05:52:40 View Details
4 Ministral 8B (LMStudio)
4900 MB
100
5333.0ms median
2026-03-03 00:23:20 View Details
5 Llama 3.2 1B (LMStudio)
1300 MB
100
1449.0ms median
2026-03-03 00:16:13 View Details
6 Llama 3 8B (LMStudio)
4900 MB
100
4749.0ms median
2026-03-03 00:13:28 View Details
7 Granite 3.2 8B (LMStudio)
4900 MB
100
5841.0ms median
2026-03-02 23:55:42 View Details
8 Gemma 3 12B (LMStudio)
8100 MB
100
9981.0ms median
2026-03-02 23:44:03 View Details
9 Gemma 2 9B (LMStudio)
5800 MB
100
7248.0ms median
2026-03-02 23:10:20 View Details
10 Llama 3.1 8B (LMStudio)
4900 MB
100
13036.0ms median
2026-03-02 20:43:55 View Details
11 GPT-5 mini
100
2911.0ms median
2026-03-02 18:02:33 View Details
12 GPT-5 nano
100
1463.0ms median
2026-03-02 18:01:50 View Details
13 Gemma 4 E4B IT (LMStudio)
3200 MB
0
5179.0ms median
2026-04-02 21:23:35 View Details
14 Qwen3.5 2B (LMStudio)
2700 MB
0
2517.0ms median
2026-03-03 19:32:35 View Details
15 Qwen3 VL 8B (LMStudio)
5000 MB
0
6000.0ms median
2026-03-03 05:50:04 View Details
16 Phi-4 (LMStudio)
9100 MB
0
8626.0ms median
2026-03-03 01:28:22 View Details
17 Phi-3.5 Mini (LMStudio)
2500 MB
0
8038.0ms median
2026-03-03 00:38:31 View Details
18 Llama 2 7B (LMStudio)
4900 MB
0
2522.0ms median
2026-03-03 00:03:32 View Details
19 Gemma 2B (LMStudio)
1500 MB
0
4930.0ms median
2026-03-02 23:14:03 View Details
20 Gemma 2 2B (LMStudio)
1500 MB
0
2393.0ms median
2026-03-02 23:01:57 View Details
21 OLMo 3 7B (LMStudio)
4300 MB
0
5780.0ms median
2026-03-02 20:30:58 View Details
22 Claude Haiku 4.5
0
842.0ms median
2026-03-02 18:00:51 View Details
Questions

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'.
Question payload
{
  "question_text": "Write Python 3.12 code only.\nDefine exactly one function named count_target_letter(text, target).\nReturn how many times the target letter appears in the string.\nCount should be case-insensitive.\nRaise TypeError for non-string input, and raise ValueError if target is not exactly one character.\nDo not use any imports (no numpy, requests, or other libraries).\nSandbox note: dunder attribute access is blocked (for example, type(x).__name__). Avoid names/attributes starting with '__'.\n\nExpected output format:\n- Return exactly one fenced Markdown code block starting with ```python and ending with ```.\n- Put only valid Python code inside that block (no prose before/after).\n- Use 4 spaces for indentation (not tabs).\n- Do not return JSON and do not wrap code in a \"function\" key.\n\nSample input/output behavior:\n- count_target_letter(\"Mississippi\", \"s\") -> 4\n\nTask:\nWrite a Python 3.12 function for 'how many times does the target letter appear in a string'.",
  "answer_type": "free_text",
  "correct_answer": {
    "function_name": "count_target_letter",
    "test_cases": [
      {
        "args": [
          "banana",
          "a"
        ],
        "expected": 3
      },
      {
        "args": [
          "Mississippi",
          "s"
        ],
        "expected": 4
      },
      {
        "args": [
          "Hello",
          "l"
        ],
        "expected": 2
      },
      {
        "args": [
          "Abracadabra",
          "a"
        ],
        "expected": 5
      },
      {
        "args": [
          "CaseSensitive",
          "c"
        ],
        "expected": 1
      },
      {
        "args": [
          "",
          "x"
        ],
        "expected": 0
      },
      {
        "args": [
          "aaaa",
          "a"
        ],
        "expected": 4
      },
      {
        "args": [
          "letter",
          "tt"
        ],
        "expected_exception": "ValueError"
      },
      {
        "args": [
          42,
          "a"
        ],
        "expected_exception": "TypeError"
      },
      {
        "args": [
          "abc",
          1
        ],
        "expected_exception": "TypeError"
      }
    ]
  },
  "category": "coding",
  "difficulty": "medium",
  "tags": [
    "python",
    "coding",
    "security"
  ],
  "evaluation_criteria": {
    "exact_match": false,
    "case_sensitive": false,
    "contains": false,
    "required_fields": [],
    "tolerance": 0.0,
    "alternatives": []
  }
}