he-023
1.000
Challenge · difficulty 1/5
# HumanEval/23
Implement a file **`solution.py`** that completes the function below. Keep the given name and signature; your file must define it at module level.
```python
def strlen(string: str) -> int:
""" Return length of given string
>>> strlen('')
0
>>> strlen('abc')
3
"""
```
<!-- imported from OpenAI HumanEval (HumanEval/23) -->
tests/test_he_023.py
# Auto-generated from OpenAI HumanEval HumanEval/23. Do not edit by hand.
from solution import * # noqa: F401,F403 (prompt helpers may be referenced by tests)
from solution import strlen as candidate
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('') == 0
assert candidate('x') == 1
assert candidate('asdasnakj') == 9
def test_he_023():
check(candidate)
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.Proposed solution
```python
def strlen(string: str) -> int:
""" Return length of given string
>>> strlen('')
0
>>> strlen('abc')
3
"""
return len(string)
```Test output (stdout)
. [100%]
1 passed in 0.01s
Reasoning (chain-of-thought)
The user wants me to implement a simple function `strlen` that returns the length of a given string.
This is a straightforward task. I'll just use Python's built-in `len()` function.
Function signature:
```python
def strlen(string: str) -> int:
""" Return length of given string
>>> strlen('')
0
>>> strlen('abc')
3
"""
return len(string)
```
I will output the solution in a fenced code block named `solution.py`.
No extra fluff.
Check constraints: "Keep the given name and signature; your file must define it at module level."
Everything matches.
Ready.
Output matches request.
Proceed.
Self-Correction/Verification:
The prompt asks for `solution.py`.
The code is trivial.
I will produce exactly that.
Done.
Output generation.
```python
def strlen(string: str) -> int:
""" Return length of given string
>>> strlen('')
0
>>> strlen('abc')
3
"""
return len(string)
```
Matches requirements.✅
Done.
Proceeds.
[Output Generation] -> *Proceeds*