benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 3b8ec50b-6c76-5ca9-be2f-b5dcc3ba7f22

Problem

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

complete prompt

import numpy as np
import random
import matplotlib.pyplot as plt

# Constants
LETTERS = list("abcdefghijklmnopqrstuvwxyz")
NUMBERS = list(range(1, 27))


def task_func(n_pairs=26):
    """
    This function generates and displays a bar chart representing random letter-number pairs.
    Each bar corresponds to a unique pair, formed by combining a letter from 'a' to 'z' with a number
    from 1 to 26. The function randomly shuffles these pairs and assigns a random count to each.

    Parameters:
    - n_pairs (int, optional): The number of letter-number pairs to display in the bar chart.
      The value must be an integer between 1 and 26, inclusive. The default value is 26, which
      includes one pair for each letter in the alphabet.

    Returns:
    - matplotlib.container.BarContainer: This object represents the bar chart created by the function.
      Each bar in the chart is labeled with its corresponding letter-number pair (e.g., 'a:1', 'b:2').
      The title of the chart is "Random Letter:Number Pairs Chart", the x-axis label is "Letter:Number Pairs",
      and the y-axis label is "Counts".

    Raises:
    - ValueError: If 'n_pairs' is outside the range of 1 to 26, inclusive. This ensures that the function
      operates within the bounds of the predefined letters ('a' to 'z') and numbers (1 to 26).

    Requirements:
    - numpy
    - matplotlib
    - random

    Notes:
    - Each call to this function will likely produce a different chart because it shuffles the order
      of the pairs and assigns random counts to them.
    - The random counts assigned to each pair range from 1 to 9.

    Example:
    >>> ax = task_func(5)
    >>> [bar.get_label() for bar in ax]
    ['d:4', 'b:2', 'c:3', 'e:5', 'a:1']
    """

instruct prompt

This function generates and displays a bar chart representing random letter-number pairs. Each bar corresponds to a unique pair, formed by combining a letter from 'a' to 'z' with a number from 1 to 26. The function randomly shuffles these pairs and assigns a random count to each.
Note that: Notes: Each call to this function will likely produce a different chart because it shuffles the order of the pairs and assigns random counts to them. The random counts assigned to each pair range from 1 to 9.
The function should raise the exception for: ValueError: If 'n_pairs' is outside the range of 1 to 26, inclusive. This ensures that the function operates within the bounds of the predefined letters ('a' to 'z') and numbers (1 to 26).
The function should output with:
    matplotlib.container.BarContainer: This object represents the bar chart created by the function.
    Each bar in the chart is labeled with its corresponding letter-number pair (e.g., 'a:1', 'b:2').
    The title of the chart is "Random Letter:Number Pairs Chart", the x-axis label is "Letter:Number Pairs",
    and the y-axis label is "Counts".
You should write self-contained code starting with:

Code

import numpy as np
import random
import matplotlib.pyplot as plt
# Constants
LETTERS = list("abcdefghijklmnopqrstuvwxyz")
NUMBERS = list(range(1, 27))
def task_func(n_pairs=26):

code prompt

Code

import numpy as np
import random
import matplotlib.pyplot as plt
# Constants
LETTERS = list("abcdefghijklmnopqrstuvwxyz")
NUMBERS = list(range(1, 27))
def task_func(n_pairs=26):

entry point

task_func

libs

  • numpy
  • matplotlib
  • 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