Skip to content

Boilerplate API

add(a, b)

Add two integers.

Parameters:

Name Type Description Default
a int

First integer.

required
b int

Second integer.

required

Returns:

Type Description
int

The sum of a and b.

Source code in python_boilerplate/main.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def add(a: int, b: int) -> int:
    """
    Add two integers.

    Args:
        a: First integer.
        b: Second integer.

    Returns:
        The sum of a and b.
    """
    return a + b

calculate_average(values)

Calculate the arithmetic mean of a list of numbers.

This function computes the average by summing all values and dividing by the number of elements.

Parameters:

Name Type Description Default
values list[float]

A non-empty list of floating-point numbers.

required

Returns:

Type Description
float

The arithmetic mean of the input values.

Raises:

Type Description
ValueError

If the input list is empty.

Examples:

>>> calculate_average([1.0, 2.0, 3.0])
2.0
Source code in python_boilerplate/main.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def calculate_average(values: list[float]) -> float:
    """
    Calculate the arithmetic mean of a list of numbers.

    This function computes the average by summing all values
    and dividing by the number of elements.

    Args:
        values: A non-empty list of floating-point numbers.

    Returns:
        The arithmetic mean of the input values.

    Raises:
        ValueError: If the input list is empty.

    Examples:
        >>> calculate_average([1.0, 2.0, 3.0])
        2.0
    """
    if not values:
        raise ValueError("values must not be empty")

    return sum(values) / len(values)