he-008
1.000
Challenge · difficulty 2/5
# HumanEval/8
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
from typing import List, Tuple
def sum_product(numbers: List[int]) -> Tuple[int, int]:
""" For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.
Empty sum should be equal to 0 and empty product should be equal to 1.
>>> sum_product([])
(0, 1)
>>> sum_product([1, 2, 3, 4])
(10, 24)
"""
```
<!-- imported from OpenAI HumanEval (HumanEval/8) -->
tests/test_he_008.py
# Auto-generated from OpenAI HumanEval HumanEval/8. Do not edit by hand.
from solution import * # noqa: F401,F403 (prompt helpers may be referenced by tests)
from solution import sum_product as candidate
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([]) == (0, 1)
assert candidate([1, 1, 1]) == (3, 1)
assert candidate([100, 0]) == (100, 0)
assert candidate([3, 5, 7]) == (3 + 5 + 7, 3 * 5 * 7)
assert candidate([10]) == (10, 10)
def test_he_008():
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
from typing import List, Tuple
def sum_product(numbers: List[int]) -> Tuple[int, int]:
sum_result = sum(numbers)
product_result = 1
for num in numbers:
product_result *= num
return (sum_result, product_result)
```Test output (stdout)
. [100%] 1 passed in 0.01s