benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf e7da1f92-01e5-5d58-88f9-d707f1e2de31

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(file_path,
          num_rows,
          gender=['Male', 'Female', 'Non-Binary'],
          countries=['USA', 'UK', 'Canada', 'Australia', 'India'],
          seed=None):
    """
    Generates a CSV file with random data for the fields ['Name', 'Age', 'Gender', 'Country'].
    The number of rows in the CSV file is determined by the 'num_rows' parameter.

    The Ages are randomly sampled integers in the range [20, 60].
    The names are generated by randomly choosing 5 uppercase characters from the english alphabet.

    
    If num_rows <= 0 a csv containing only the headers is generated.

    Parameters:
    file_path (str): The file path where the CSV file should be created.
    num_rows (int): The number of rows of random data to generate.
    gender (list of str, optional): The list of genders to sample from.
        Defaults to ['Male', 'Female', 'Non-Binary'].
    countries (list of str, optional): The list of countries to sample from.
        Defaults to ['USA', 'UK', 'Canada', 'Australia', 'India'].
    seed (int, optional): The seed used for random sampling.
        Defaults to None.

    Returns:
    str: The file path of the generated CSV file.

    Requirements:
    - csv
    - random

    Example:
    >>> task_func('/tmp/data.csv', 100)
    '/tmp/data.csv'

    >>> task_func('/test.csv', 100, gender=['test'], countries['Albania', 'Germany', 'Austria'], seed=12)
    'test.csv'
    """

instruct prompt

Generates a CSV file with random data for the fields ['Name', 'Age', 'Gender', 'Country']. The number of rows in the CSV file is determined by the 'num_rows' parameter. The Ages are randomly sampled integers in the range [20, 60]. The names are generated by randomly choosing 5 uppercase characters from the english alphabet. If num_rows <= 0 a csv containing only the headers is generated. >>> task_func('/test.csv', 100, gender=['test'], countries['Albania', 'Germany', 'Austria'], seed=12) 'test.csv'
The function should output with:
    str: The file path of the generated CSV file.
You should write self-contained code starting with:

Code

import csv
import random
def task_func(file_path,
          num_rows,
          gender=['Male', 'Female', 'Non-Binary'],
          countries=['USA', 'UK', 'Canada', 'Australia', 'India'],
          seed=None):

code prompt

Code

import csv
import random
def task_func(file_path,
          num_rows,
          gender=['Male', 'Female', 'Non-Binary'],
          countries=['USA', 'UK', 'Canada', 'Australia', 'India'],
          seed=None):

entry point

task_func

libs

  • csv
  • random

Discussion

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

Official source

initial import