package_name_to_import_with.calculator_sub_package package#

Subpackages#

Submodules#

Module contents#

Expose binary operations.

class BinaryArithmeticExpression(*, left_operand, binary_operator, right_operand)[source]#

Bases: pydantic.main.BaseModel

Define binary arithmetic expression.

left_operand#

first number of binary arithmetic expression

Type:

float

binary_operator#

arithmetic operator of binary arithmetic expression

Type:

BinaryArithmeticOperator

right_operand#

second number of binary arithmetic expression

Type:

float

operation#

function to perform arithmetic operation corresponding to self.binary_operator

Type:

BinaryArithmeticOperation

result#

result of binary arithmetic expression

Type:

float

left_operand: float#
binary_operator: package_name_to_import_with.calculator_sub_package.wrapper_module.BinaryArithmeticOperator#
right_operand: float#
property operation: collections.abc.Callable[[float, float], float]#

Store implementation of binary arithmetic operation.

Returns:

implementation of binary arithmetic operation corresponding to self.binary_operator

Return type:

BinaryArithmeticOperation

property result: float#

Store result of binary arithmetic expression.

Returns:

result of binary arithmetic expression

Return type:

float

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}#

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'binary_operator': FieldInfo(annotation=BinaryArithmeticOperator, required=True), 'left_operand': FieldInfo(annotation=float, required=True), 'right_operand': FieldInfo(annotation=float, required=True)}#

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

BinaryArithmeticOperation#

alias of collections.abc.Callable[float, float, float]

class BinaryArithmeticOperator(value)[source]#

Bases: str, enum.Enum

Define supported arithmetic operators.

ADDITION = '+'#
SUBTRACTION = '-'#
MULTIPLICATION = '*'#
DIVISION = '/'#
class IdentityElements(value)[source]#

Bases: float, enum.Enum

Define assumed identity elements.

ADDITIVE_IDENTITY = 0.0#
MULTIPLICATIVE_IDENTITY = 1.0#
class InverseElements(value)[source]#

Bases: float, enum.Enum

Define supported inverse elements.

ADDITIVE_INVERSE = -1.0#
MULTIPLICATIVE_INVERSE = 1.0#
add_numbers(left_addend, right_addend)[source]#

Perform addition of two real numbers.

Parameters:
  • left_addend (float) -- first number to be added

  • right_addend (float) -- second number to be added

Returns:

sum of left_addend and right_addend

Return type:

float

Examples

>>> from package_name_to_import_with.calculator_sub_package import add_numbers
>>> add_numbers(1, 2)
3.0
>>> add_numbers(1, -2)
-1.0
>>> add_numbers(-1, 2)
1.0
>>> add_numbers(-1, -2)
-3.0
calculate_results(first_input, operator, second_input)[source]#

Perform basic binary arithmetic expressions.

Parameters:
  • first_input (float) -- left operand of binary arithmetic expression

  • operator (BinaryArithmeticOperator) -- kind of binary arithmetic expression

  • second_input (float) -- right operand of binary arithmetic expression

Returns:

result of binary arithmetic expression

Return type:

float

Examples

>>> from package_name_to_import_with import calculate_results
>>> calculate_results(1, "+", 2)
3.0
>>> calculate_results(1, "-", 2)
-1.0
>>> calculate_results(1, "*", 2)
2.0
>>> calculate_results(1, "/", 2)
0.5
divide_numbers(dividend, divisor)[source]#

Perform division of two real numbers.

Parameters:
  • dividend (float) -- number which is divided

  • divisor (float) -- number which divides

Returns:

quotient of dividend by divisor

Return type:

float

Examples

>>> from package_name_to_import_with.calculator_sub_package import divide_numbers
>>> divide_numbers(1, 2)
0.5
>>> divide_numbers(1, -2)
-0.5
>>> divide_numbers(-1, 2)
-0.5
>>> divide_numbers(-1, -2)
0.5
get_negative(input_number)[source]#

Get additive inverse of a real number.

Parameters:

input_number (float) -- number for which additive inverse is required

Returns:

negative of input_number

Return type:

float

Examples

>>> from package_name_to_import_with.calculator_sub_package import get_negative
>>> get_negative(1)
-1.0
>>> get_negative(-1)
1.0
get_reciprocal(input_number)[source]#

Get multiplicative inverse of a real number.

Parameters:

input_number (float) -- number for which multiplicative inverse is required

Returns:

reciprocal of input_number

Return type:

float

Raises:

ValueError -- if input_number is additive identity, viz. zero

Examples

>>> from package_name_to_import_with.calculator_sub_package import get_reciprocal
>>> get_reciprocal(2)
0.5
>>> get_reciprocal(0.5)
2.0
multiply_numbers(left_multiplicand, right_multiplicand)[source]#

Perform multiplication of two real numbers.

Parameters:
  • left_multiplicand (float) -- first number to be multiplied

  • right_multiplicand (float) -- second number to be multiplied

Returns:

product of two left_multiplicand and right_multiplicand

Return type:

float

Examples

>>> from package_name_to_import_with.calculator_sub_package import multiply_numbers
>>> multiply_numbers(1, 2)
2.0
>>> multiply_numbers(1, -2)
-2.0
>>> multiply_numbers(-1, 2)
-2.0
>>> multiply_numbers(-1, -2)
2.0
subtract_numbers(minuend, subtrahend)[source]#

Perform subtraction of two real numbers.

Parameters:
  • minuend (float) -- number which is subtracted from

  • subtrahend (float) -- number which is subtracted

Returns:

difference of minuend from subtrahend

Return type:

float

Examples

>>> from package_name_to_import_with.calculator_sub_package import subtract_numbers
>>> subtract_numbers(1, 2)
-1.0
>>> subtract_numbers(1, -2)
3.0
>>> subtract_numbers(-1, 2)
-3.0
>>> subtract_numbers(-1, -2)
1.0