benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf fa9072c4-4761-580f-af20-d02dc241de89

Problem

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

complete prompt

import json
import requests

def task_func(API_URL, endpoint, PREFIX):
    """
    Retrieves JSON data from a specified API endpoint and writes it to a file. The filename is generated by concatenating 
    a provided prefix with the endpoint name, followed by '.json'.

    Parameters:
    - API_URL (str): The base URL of the API.
    - endpoint (str): The specific API endpoint to retrieve data from.
    - PREFIX (str): The prefix to prepend to the filename for the output JSON file.

    Returns:
    - str: The filename into which the JSON data was written.

    Requirements:
    - json
    - requests

    Raises:
    - RuntimeError: If there is an error fetching data from the API or writing to the file.

    Example:
    >>> filename = task_func('https://api.github.com/', 'users', 'ME')
    >>> print(filename)
    'MEusers.json'
    """

instruct prompt

Retrieves JSON data from a specified API endpoint and writes it to a file. The filename is generated by concatenating a provided prefix with the endpoint name, followed by '.json'.
The function should raise the exception for: RuntimeError: If there is an error fetching data from the API or writing to the file.
The function should output with:
    str: The filename into which the JSON data was written.
You should write self-contained code starting with:

Code

import json
import requests
def task_func(API_URL, endpoint, PREFIX):

code prompt

Code

import json
import requests
def task_func(API_URL, endpoint, PREFIX):

entry point

task_func

libs

  • requests
  • json

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