package_name_to_import_with.calculator_sub_package.wrapper_module module#

Define function for basic 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 = '/'#
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