Skip to content

API documentation#

Square#

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))

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

UI#

Init for ui.

Number #

Number

A representation of a number.

Attributes:

Name Type Description
x int | float

Value of the object.

Raises:

Type Description
NumberError

X must be a valid number.

Source code in template_package/ui/accepted_headers.py
class Number:
    """Number

    A representation of a number.

    Attributes:
        x (int | float): Value of the object.

    Raises:
        NumberError: X must be a valid number.
    """

    def __init__(self, x: int | float) -> None:
        if not isinstance(x, Number | int | float):
            raise NumberError("Not a valid number.")
        if isinstance(x, Number):
            x = x.x
        self.x: int | float = x

    def __pow__(
        self,
        power: int | float | Number,
        modulo: int | float | Number | None = None,
    ) -> Number:
        """
        Takes x to the power of power moduls modulo.
        Then puts value into a Number class form.

        Args:
            power (int | float | Number): Value for self.x to be raised to.
            modulo (int | float | Number | None): Modulus. Default is None.

        Returns:
            Number: Returns a new instance of Number with x being the result.
        """
        if isinstance(power, type(self)):
            power = power.x
        if isinstance(modulo, type(self)):
            modulo = modulo.x
        if modulo is None:
            return Number(self.x**power)
        if (not isinstance(modulo, int)) and (modulo is not None):
            modulo = int(round(modulo))
        return Number((self.x**power) % modulo)

    def __eq__(self, other):
        if isinstance(other, type(self)):
            return self.x == other.x
        elif isinstance(other, int | float):
            return self.x == other
        else:
            return NotImplemented

__pow__(power, modulo=None) #

Takes x to the power of power moduls modulo. Then puts value into a Number class form.

Parameters:

Name Type Description Default
power int | float | Number

Value for self.x to be raised to.

required
modulo int | float | Number | None

Modulus. Default is None.

None

Returns:

Name Type Description
Number Number

Returns a new instance of Number with x being the result.

Source code in template_package/ui/accepted_headers.py
def __pow__(
    self,
    power: int | float | Number,
    modulo: int | float | Number | None = None,
) -> Number:
    """
    Takes x to the power of power moduls modulo.
    Then puts value into a Number class form.

    Args:
        power (int | float | Number): Value for self.x to be raised to.
        modulo (int | float | Number | None): Modulus. Default is None.

    Returns:
        Number: Returns a new instance of Number with x being the result.
    """
    if isinstance(power, type(self)):
        power = power.x
    if isinstance(modulo, type(self)):
        modulo = modulo.x
    if modulo is None:
        return Number(self.x**power)
    if (not isinstance(modulo, int)) and (modulo is not None):
        modulo = int(round(modulo))
    return Number((self.x**power) % modulo)

NumberError #

Bases: TypeError

Invalid type for Number class.

Source code in template_package/ui/accepted_headers.py
class NumberError(TypeError):
    """
    Invalid type for Number class.
    """

    pass

Admonition#

Warning#

Warning

This is a warning message.

Note#

Note

This is a notice message.


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