benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 516305c1-8074-52c0-bcaf-71512093f9f4
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import csv
import random
def task_func(csv_file='names.csv',
latin_names=['Sopetón', 'Méndez', 'Gómez', 'Pérez', 'Muñoz'],
names=['Smith', 'Johnson', 'Williams', 'Brown', 'Jones'],
encoding='latin-1', rng_seed=None):
"""
Create a CSV file with 100 lines. Each line contains a name and an age (randomly generated between 20 and 50).
Half of the names are randomly selected from a list of Latin names (default: ['Sopetón', 'Méndez', 'Gómez', 'Pérez', 'Muñoz']),
the other half from a list of English names (default: ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones']).
All names are encoded using the specified encoding.
If empty name arrays are passed, a csv with headers but no entries is generated.
Args:
- csv_file (str, optional): Name of the CSV file to be created. Defaults to 'names.csv'.
- latin_names (list, optional): List of Latin names. Defaults to ['Sopetón', 'Méndez', 'Gómez', 'Pérez', 'Muñoz'].
- names (list, optional): List of English names. Defaults to ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones'].
- encoding (str, optional): The encoding used for writing the names. Defaults to 'latin-1'
- rng_seed (int, optional): The seed for the rng. Defaults to None.
Returns:
- str: The CSV file name.
Raises:
- TypeError: If csv_file is not a string.
- TypeError: If latin_names is not an array.
- TypeError: If names is not an array.
Requirements:
- csv
- random
Example:
>>> file_name = task_func()
>>> print(file_name)
names.csv
>>> file_name = task_func(csv_file='test.csv', names=['simon', 'alex'], rng_seed=1)
>>> with open(file_name, 'r', newline='', encoding='latin-1') as csvfile:
... reader = csv.reader(csvfile)
... rows = list(reader)
... print(rows)
[['Name', 'Age'], ['Méndez', '38'], ['simon', '28'], ['Sopetón', '35'], ['alex', '35'], ['Pérez', '45'], ['simon', '23'], ['Pérez', '20'], ['alex', '33'], ['Muñoz', '44'], ['simon', '42'], ['Pérez', '28'], ['simon', '38'], ['Sopetón', '48'], ['alex', '20'], ['Sopetón', '20'], ['simon', '50'], ['Pérez', '41'], ['simon', '33'], ['Sopetón', '36'], ['simon', '44'], ['Pérez', '50'], ['alex', '37'], ['Méndez', '31'], ['simon', '41'], ['Méndez', '44'], ['alex', '50'], ['Gómez', '49'], ['simon', '33'], ['Muñoz', '49'], ['simon', '25'], ['Gómez', '23'], ['alex', '48'], ['Muñoz', '49'], ['alex', '36'], ['Méndez', '29'], ['alex', '38'], ['Pérez', '47'], ['alex', '38'], ['Sopetón', '35'], ['simon', '43'], ['Pérez', '33'], ['simon', '31'], ['Muñoz', '48'], ['alex', '22'], ['Pérez', '41'], ['simon', '44'], ['Méndez', '36'], ['alex', '31'], ['Pérez', '43'], ['simon', '35'], ['Sopetón', '29'], ['alex', '40'], ['Méndez', '25'], ['simon', '20'], ['Méndez', '37'], ['simon', '32'], ['Muñoz', '31'], ['alex', '34'], ['Gómez', '41'], ['simon', '32'], ['Muñoz', '45'], ['simon', '36'], ['Muñoz', '26'], ['alex', '50'], ['Sopetón', '35'], ['alex', '38'], ['Muñoz', '26'], ['alex', '35'], ['Gómez', '33'], ['alex', '20'], ['Muñoz', '37'], ['alex', '34'], ['Muñoz', '20'], ['simon', '40'], ['Méndez', '37'], ['simon', '47'], ['Sopetón', '45'], ['alex', '21'], ['Sopetón', '22'], ['simon', '34'], ['Sopetón', '44'], ['alex', '27'], ['Gómez', '23'], ['simon', '31'], ['Gómez', '22'], ['simon', '25'], ['Gómez', '36'], ['simon', '41'], ['Gómez', '40'], ['alex', '34'], ['Gómez', '35'], ['alex', '23'], ['Sopetón', '29'], ['alex', '30'], ['Pérez', '45'], ['simon', '28'], ['Sopetón', '28'], ['simon', '50'], ['Muñoz', '33'], ['simon', '27']]
"""
instruct prompt
Create a CSV file with 100 lines. Each line contains a name and an age (randomly generated between 20 and 50). Half of the names are randomly selected from a list of Latin names (default: ['Sopetón', 'Méndez', 'Gómez', 'Pérez', 'Muñoz']), the other half from a list of English names (default: ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones']). All names are encoded using the specified encoding. If empty name arrays are passed, a csv with headers but no entries is generated. Args: - csv_file (str, optional): Name of the CSV file to be created. Defaults to 'names.csv'. - latin_names (list, optional): List of Latin names. Defaults to ['Sopetón', 'Méndez', 'Gómez', 'Pérez', 'Muñoz']. - names (list, optional): List of English names. Defaults to ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones']. - encoding (str, optional): The encoding used for writing the names. Defaults to 'latin-1' - rng_seed (int, optional): The seed for the rng. Defaults to None. >>> file_name = task_func(csv_file='test.csv', names=['simon', 'alex'], rng_seed=1) >>> with open(file_name, 'r', newline='', encoding='latin-1') as csvfile: ... reader = csv.reader(csvfile) ... rows = list(reader) ... print(rows) [['Name', 'Age'], ['Méndez', '38'], ['simon', '28'], ['Sopetón', '35'], ['alex', '35'], ['Pérez', '45'], ['simon', '23'], ['Pérez', '20'], ['alex', '33'], ['Muñoz', '44'], ['simon', '42'], ['Pérez', '28'], ['simon', '38'], ['Sopetón', '48'], ['alex', '20'], ['Sopetón', '20'], ['simon', '50'], ['Pérez', '41'], ['simon', '33'], ['Sopetón', '36'], ['simon', '44'], ['Pérez', '50'], ['alex', '37'], ['Méndez', '31'], ['simon', '41'], ['Méndez', '44'], ['alex', '50'], ['Gómez', '49'], ['simon', '33'], ['Muñoz', '49'], ['simon', '25'], ['Gómez', '23'], ['alex', '48'], ['Muñoz', '49'], ['alex', '36'], ['Méndez', '29'], ['alex', '38'], ['Pérez', '47'], ['alex', '38'], ['Sopetón', '35'], ['simon', '43'], ['Pérez', '33'], ['simon', '31'], ['Muñoz', '48'], ['alex', '22'], ['Pérez', '41'], ['simon', '44'], ['Méndez', '36'], ['alex', '31'], ['Pérez', '43'], ['simon', '35'], ['Sopetón', '29'], ['alex', '40'], ['Méndez', '25'], ['simon', '20'], ['Méndez', '37'], ['simon', '32'], ['Muñoz', '31'], ['alex', '34'], ['Gómez', '41'], ['simon', '32'], ['Muñoz', '45'], ['simon', '36'], ['Muñoz', '26'], ['alex', '50'], ['Sopetón', '35'], ['alex', '38'], ['Muñoz', '26'], ['alex', '35'], ['Gómez', '33'], ['alex', '20'], ['Muñoz', '37'], ['alex', '34'], ['Muñoz', '20'], ['simon', '40'], ['Méndez', '37'], ['simon', '47'], ['Sopetón', '45'], ['alex', '21'], ['Sopetón', '22'], ['simon', '34'], ['Sopetón', '44'], ['alex', '27'], ['Gómez', '23'], ['simon', '31'], ['Gómez', '22'], ['simon', '25'], ['Gómez', '36'], ['simon', '41'], ['Gómez', '40'], ['alex', '34'], ['Gómez', '35'], ['alex', '23'], ['Sopetón', '29'], ['alex', '30'], ['Pérez', '45'], ['simon', '28'], ['Sopetón', '28'], ['simon', '50'], ['Muñoz', '33'], ['simon', '27']]
The function should raise the exception for: TypeError: If csv_file is not a string. TypeError: If latin_names is not an array. TypeError: If names is not an array.
The function should output with:
str: The CSV file name.
You should write self-contained code starting with:
Code
import csv
import random
def task_func(csv_file='names.csv',
latin_names=['Sopetón', 'Méndez', 'Gómez', 'Pérez', 'Muñoz'],
names=['Smith', 'Johnson', 'Williams', 'Brown', 'Jones'],
encoding='latin-1', rng_seed=None):
code prompt
Code
import csv
import random
def task_func(csv_file='names.csv',
latin_names=['Sopetón', 'Méndez', 'Gómez', 'Pérez', 'Muñoz'],
names=['Smith', 'Johnson', 'Williams', 'Brown', 'Jones'],
encoding='latin-1', rng_seed=None):
entry point
task_func
libs
- csv
- random
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import