package_name_to_import_with.calculator_sub_package.wrapper_module module#
Define function for basic binary operations.
- pydantic model BinaryArithmeticExpression[source]#
Bases:
CustomPydanticBaseModelDefine binary arithmetic expression.
- binary_operator#
arithmetic operator of binary arithmetic expression
- Type:
- operation#
function to perform arithmetic operation corresponding to binary_operator
Show JSON schema
{ "title": "BinaryArithmeticExpression", "description": "Define binary arithmetic expression.\n\nAttributes\n----------\nleft_operand : float\n first number of binary arithmetic expression\nbinary_operator : BinaryArithmeticOperator\n arithmetic operator of binary arithmetic expression\nright_operand : float\n second number of binary arithmetic expression\noperation : BinaryArithmeticOperation\n function to perform arithmetic operation corresponding to `binary_operator`\nresult : float\n result of binary arithmetic expression", "type": "object", "properties": { "left_operand": { "description": "first number of binary arithmetic expression", "title": "Left Operand", "type": "number" }, "binary_operator": { "allOf": [ { "$ref": "#/$defs/BinaryArithmeticOperator" } ], "description": "arithmetic operator of binary arithmetic expression" }, "right_operand": { "description": "second number of binary arithmetic expression", "title": "Right Operand", "type": "number" } }, "$defs": { "BinaryArithmeticOperator": { "description": "Define supported arithmetic operators.", "enum": [ "+", "-", "*", "/" ], "title": "BinaryArithmeticOperator", "type": "string" } }, "additionalProperties": false, "required": [ "left_operand", "binary_operator", "right_operand" ] }
- Config:
extra: str = forbid
- Fields:
- Validators:
validate_zero_division»all fields
- field binary_operator: BinaryArithmeticOperator [Required]#
arithmetic operator of binary arithmetic expression
- Validated by:
- validator validate_zero_division » all fields[source]#
Validate that division by zero is not attempted.
- Returns:
unchanged instance if validation passes
- Return type:
- Raises:
ValueError -- if division by zero is attempted
- Validates:
all fields
- property operation: Callable[[float, float], float]#
Store implementation of binary arithmetic operation.
- Returns:
implementation of binary arithmetic operation corresponding to 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]] = {'operation': ComputedFieldInfo(wrapped_property=<property object>, return_type=collections.abc.Callable[[float, float], float], alias=None, alias_priority=None, title=None, description='Store implementation of binary arithmetic operation.\n\nReturns\n-------\nBinaryArithmeticOperation\n implementation of binary arithmetic operation corresponding to `binary_operator`', examples=None, json_schema_extra=None, repr=True), 'result': ComputedFieldInfo(wrapped_property=<functools.cached_property object>, return_type=<class 'float'>, alias=None, alias_priority=None, title=None, description='Store result of binary arithmetic expression.\n\nReturns\n-------\nfloat\n result of binary arithmetic expression', examples=None, json_schema_extra=None, repr=True)}#
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- class BinaryArithmeticOperator(value)[source]#
Bases:
CustomStrEnumDefine supported arithmetic operators.
- ADDITION = '+'#
- SUBTRACTION = '-'#
- MULTIPLICATION = '*'#
- DIVISION = '/'#
- calculate_results(first_input: float, operator: BinaryArithmeticOperator, second_input: float) float[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