benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf dd549f0e-3b86-5543-b03a-8da6b8c084d2

Problem

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

complete prompt

import random
import matplotlib.pyplot as plt


# Sample data
class Object:
    value = 0

    def __init__(self, value=None):
        if value is None:
            self.value = random.gauss(0, 1)
        else:
            self.value = value


def task_func(obj_list, attr, num_bins=30, seed=0):
    """
    Create a histogram of the specified attribute from a list of objects and return the histogram plot.

    Parameters:
    obj_list (list): The list of objects containing the attribute.
    attr (str): The attribute to generate a histogram for.
    num_bins (int, Optional): The number of bins to use in the histogram. Defaults to 30.
    seed (int, Optional): The seed for the random number generator. Defaults to 0.

    Returns:
    matplotlib.axes._axes.Axes: The histogram plot of the attribute values, with the title 'Histogram of attribute values', x-axis labeled 'Attribute Value', and y-axis labeled 'Count'.

    Requirements:
    - random (used for default object generation)
    - numpy (used for numerical computations)
    - matplotlib (used for plotting)

    Constants:
    - NUM_BINS (int): Number of bins to use in the histogram, set to 30 by default.

    Example:
    >>> obj_list = [Object(value=i) for i in range(10)]
    >>> ax = task_func(obj_list, 'value')
    >>> type(ax)
    <class 'matplotlib.axes._axes.Axes'>
    """

instruct prompt

Create a histogram of the specified attribute from a list of objects and return the histogram plot. Constants: - NUM_BINS (int): Number of bins to use in the histogram, set to 30 by default.
The function should output with:
    matplotlib.axes._axes.Axes: The histogram plot of the attribute values, with the title 'Histogram of attribute values', x-axis labeled 'Attribute Value', and y-axis labeled 'Count'.
You should write self-contained code starting with:

Code

import random
import matplotlib.pyplot as plt
# Sample data
class Object:
    value = 0
    def __init__(self, value=None):
        if value is None:
            self.value = random.gauss(0, 1)
        else:
            self.value = value
def task_func(obj_list, attr, num_bins=30, seed=0):

code prompt

Code

import random
import matplotlib.pyplot as plt
# Sample data
class Object:
    value = 0
    def __init__(self, value=None):
        if value is None:
            self.value = random.gauss(0, 1)
        else:
            self.value = value
def task_func(obj_list, attr, num_bins=30, seed=0):

entry point

task_func

libs

  • random
  • matplotlib

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