benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf b0b08534-eed8-5c30-96cb-eaebb10a55ad

Problem

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

complete prompt

import os
import random

def task_func(directory, n_files):
    """
    Create n random txt files in a specific directory, write only a single digit random integer into each file, and then reset the cursor to the beginning of each file.
    The file names start from 'file_1.txt' and increment by 1 for each file.
    
    Parameters:
    - directory (str): The directory in which to generate the files.
    - n_files (int): The number of files to generate.

    Returns:
    - n_files (int): The number of files generated.

    Requirements:
    - os
    - random

    Example:
    >>> random.seed(2)
    >>> task_func('/path/to/directory', 5)
    5
    """

instruct prompt

Create n random txt files in a specific directory, write only a single digit random integer into each file, and then reset the cursor to the beginning of each file. The file names start from 'file_1.txt' and increment by 1 for each file.
The function should output with:
    n_files (int): The number of files generated.
You should write self-contained code starting with:

Code

import os
import random
def task_func(directory, n_files):

code prompt

Code

import os
import random
def task_func(directory, n_files):

entry point

task_func

libs

  • random
  • os

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