benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf f8e7796f-ace9-506d-8376-cfe3be447660

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import sqlite3
import random


def task_func(db_path,
          num_entries,
          users=['Alice', 'Bob', 'Charlie', 'Dave', 'Eve'],
          countries=['USA', 'UK', 'Canada', 'Australia', 'India'],
          random_seed=None):
    """
    Generate an SQLite database to a given file path with random user data.

    The user data consists of a table named 'users' with columns:
        - id (integer): Used as Primary Key. numbering of entries starting at 0.
        - name (string): name of the user. sampled from 'users'
        - age (int): age of the user, where 20 <= age <= 60.
        - country (string): sampled from 'countries'

    The number of entries in the database is determined by num_entries.

    Parameters:
    db_path (str): The file path where the SQLite database should be created.
    num_entries (int): The number of entries of random data to generate.
    users (list of str, optional): List of user names to choose from. Defaults to ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve'].
    countries (list of str, optional): List of countries to choose from. Defaults to ['USA', 'UK', 'Canada', 'Australia', 'India'].
    random_seed (int, optional): Seed used in rng. Defaults to Nonee.
    
    Returns:
    str: The file path of the generated SQLite database.

    Requirements:
    - sqlite3
    - random

    Example:
    >>> task_func('/tmp/users.db', 100)
    '/tmp/users.db'

    >>> path = task_func('test.db', num_entries=3, random_seed=2, users=['Simon', 'Albert'])
    >>> conn = sqlite3.connect('test.db')
    >>> c = conn.cursor()
    >>> c.execute("SELECT * FROM users")
    >>> c.fetchall()
    [(1, 'Simon', 25, 'USA'), (2, 'Viola', 30, 'Canada'), (3, 'Viola', 58, 'UK')]
    >>> c.execute("PRAGMA table_info(users)")
    >>> c.fetchall()
    [(0, 'id', 'INTEGER', 0, None, 1),
    (1, 'name', 'TEXT', 0, None, 0),
    (2, 'age', 'INTEGER', 0, None, 0),
    (3, 'country', 'TEXT', 0, None, 0)]
    """

instruct prompt

Generate an SQLite database to a given file path with random user data. The user data consists of a table named 'users' with columns: - id (integer): Used as Primary Key. numbering of entries starting at 0. - name (string): name of the user. sampled from 'users' - age (int): age of the user, where 20 <= age <= 60. - country (string): sampled from 'countries' The number of entries in the database is determined by num_entries. >>> path = task_func('test.db', num_entries=3, random_seed=2, users=['Simon', 'Albert']) >>> conn = sqlite3.connect('test.db') >>> c = conn.cursor() >>> c.execute("SELECT * FROM users") >>> c.fetchall() [(1, 'Simon', 25, 'USA'), (2, 'Viola', 30, 'Canada'), (3, 'Viola', 58, 'UK')] >>> c.execute("PRAGMA table_info(users)") >>> c.fetchall() [(0, 'id', 'INTEGER', 0, None, 1), (1, 'name', 'TEXT', 0, None, 0), (2, 'age', 'INTEGER', 0, None, 0), (3, 'country', 'TEXT', 0, None, 0)]
The function should output with:
    str: The file path of the generated SQLite database.
You should write self-contained code starting with:

Code

import sqlite3
import random
def task_func(db_path,
          num_entries,
          users=['Alice', 'Bob', 'Charlie', 'Dave', 'Eve'],
          countries=['USA', 'UK', 'Canada', 'Australia', 'India'],
          random_seed=None):

code prompt

Code

import sqlite3
import random
def task_func(db_path,
          num_entries,
          users=['Alice', 'Bob', 'Charlie', 'Dave', 'Eve'],
          countries=['USA', 'UK', 'Canada', 'Australia', 'India'],
          random_seed=None):

entry point

task_func

libs

  • sqlite3
  • 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