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.
- binary_operator#
arithmetic operator of binary arithmetic expression
- Type:
- operation#
function to perform arithmetic operation corresponding to
self.binary_operator
- binary_operator: package_name_to_import_with.calculator_sub_package.wrapper_module.BinaryArithmeticOperator#
- 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:
- property result: float#
Store result of binary arithmetic expression.
- Returns:
result of binary arithmetic expression
- Return type:
- 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]#
-
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 expressionoperator (
BinaryArithmeticOperator
) -- kind of binary arithmetic expressionsecond_input (
float
) -- right operand of binary arithmetic expression
- Returns:
result of binary arithmetic expression
- Return type:
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