Skip to content

Full#

Template Package

Pi #

Value of pi to set decimal value.

Source code in template_package/stubby/idk.py
class Pi:
    """Value of pi to set decimal value."""

    def __init__(self, number_of_decimals: int = 2) -> None:
        self.n_values: int = number_of_decimals

    def round(self, number_of_decimals: Optional[int] = None) -> Pi:
        """
        Set rounding value for pi.

        Args:
            number_of_decimals (int): Number of decimal places.

        Returns:
            Pi: self

        Raises:
            TypeError: Number of decimal places must be an integer.
        """
        if not isinstance(number_of_decimals, int):
            raise TypeError("Number of decimal places must be an integer.")
        self.n_values = number_of_decimals
        return self

    @property
    def pi(self) -> float:
        """
        pi

        Returns:
            float: Rounded to the set value of the decimal places.
        """
        return round(math.pi, self.n_values)

pi: float property #

pi

Returns:

Name Type Description
float float

Rounded to the set value of the decimal places.

round(number_of_decimals=None) #

Set rounding value for pi.

Parameters:

Name Type Description Default
number_of_decimals int

Number of decimal places.

None

Returns:

Name Type Description
Pi Pi

self

Raises:

Type Description
TypeError

Number of decimal places must be an integer.

Source code in template_package/stubby/idk.py
def round(self, number_of_decimals: Optional[int] = None) -> Pi:
    """
    Set rounding value for pi.

    Args:
        number_of_decimals (int): Number of decimal places.

    Returns:
        Pi: self

    Raises:
        TypeError: Number of decimal places must be an integer.
    """
    if not isinstance(number_of_decimals, int):
        raise TypeError("Number of decimal places must be an integer.")
    self.n_values = number_of_decimals
    return self

main() #

The main function for the module.

Squares the first 50 integer numbers.

Returns:

Name Type Description
int int

Exit code

Source code in template_package/__main__.py
def main() -> int:
    """
    The main function for the module.

    Squares the first 50 integer numbers.

    Returns:
        int: Exit code
    """
    for idx in range(50):
        square(Number(idx))
    return 0

square(x) #

Squares the given number.

Parameters:

Name Type Description Default
x Number

A real positive or negative number.

required

Returns:

Name Type Description
Number Number

The square of the given number.

Raises:

Type Description
TypeError

If the given number is not a number.

Source code in template_package/__main__.py
def square(x: Number | int | float) -> Number:
    """
    Squares the given number.

    Args:
        x (Number): A real positive or negative number.

    Returns:
        Number: The square of the given number.

    Raises:
        TypeError: If the given number is not a number.
    """
    if isinstance(x, int | float):
        x = Number(x)
    return Number(pow(x, 2))

Last update: March 14, 2023
Created: March 14, 2023