Package: sk-reporter
CalculatorThis is a advanced calculator program that can evaluate arithmetic expressions and perform trigonometric calculations. It provides the following functionality:Arithmetic operations: addition, subtraction, multiplication, and divisionSupport for complex expressions with multiple operatorsUnary operators: positive and negative signsEvaluation of expressions inside bracketsTrigonometric functions: sin, cos, tan, cosec, sec, and cotInverse trigonometric functions: asin, acos, atanGetting StartedInstall by commandpip install sk_calculatorUsageTo evaluate an arithmetic expression, create an instance of theCalculatorclass and call theevaluatemethod, passing the expression as a string parameter. The method will return the result of the evaluation.Here's an example:fromsk_calculatorimportCalculator# Create an instance of the Calculator classcalculator=Calculator()# Evaluate an arithmetic expressionresult=calculator.evaluate('2 + 3 * 4')print(result)# Output: 14You can use theevaluatemethod to perform various calculations, including complex expressions and trigonometric functions.Supported OperationsArithmetic OperationsThe calculator supports the following arithmetic operations:Addition:+Subtraction:-Multiplication:*Division:/Power:^Module:%Unary OperatorsThe calculator supports unary operators to represent positive and negative numbers:Positive:+Negative:-Evaluation of ExpressionsThe calculator can evaluate complex expressions with multiple operators and parentheses. It follows the standard order of operations (PEMDAS/BODMAS).Here's an example:result=calculator.evaluate('(2 + 3) * 4')print(result)# Output: 20Trigonometric FunctionsThe calculator provides trigonometric functions to calculate sine, cosine, tangent, cosecant, secant, and cotangent. The functions are case-insensitive.Sine:sinCosine:cosTangent:tanCosecant:cosecSecant:secCotangent:cotHere's an example:result=calculator.evaluate('sin(45) + cos(30)')print(result)# Output: 1.573132185Inverse Trigonometric FunctionsThe calculator also supports inverse trigonometric functions to calculate arcsine, arccosine, and arctangent. The functions are case-insensitive.Arcsine:asinArccosine:acosArctangent:atanArcCosecant:acosecArcSecant:asecArcCotangent:acotHere's an example:result=calculator.evaluate('atan(1)')print(result)# Output: 45.0Additional FunctionsThe calculator also supports the following additional functions:Square Root:sqrt(x), wherexis the number for which you want to calculate the square root. Example:sqrt(16)returns4.Absolute Value:abs(x), wherexis the number for which you want to calculate the absolute value. Example:abs(-5)returns5.Exponential:exp(x), wherexis the number for which you want to calculate the exponential value. Example:exp(2)returns7.3890560989306495.Logarithm:logx(y), wherexis the base andyis the number for which you want to calculate the logarithm. Example:log10(100)returns2.
Here's an example that includes the usage of these additional functions:result=calculator.evaluate('sqrt(16) + abs(-5) * exp(2)')print(result)# Output: 40.945280495ValidationsThe supported validations in yourcalculator.pyprogram are designed to check for various types of errors and ensure that the input expression is valid. Here is a description of each supported validation:Complex Expression: This validation tests the evaluation of a complex expression involving multiple arithmetic operations. It verifies that the evaluated result matches the expected expression.Type Error: This validation checks for an empty expression. If the expression is empty, it returns an error message indicating that the expression is empty.Parentheses Error: This validation identifies errors related to parentheses in the expression. It checks for missing or mismatched opening and closing parentheses and returns appropriate error messages.Function Error: This validation detects errors related to function calls. It checks for empty function calls and returns an error message indicating that the function call is empty.Keyword: This validation verifies the correctness of function names and keywords used in the expression. It checks for inappropriate function calls and invalid keywords, returning corresponding error messages.Invalid Operators Error: This validation identifies errors related to invalid operators in the expression. It checks for unsupported or invalid operator combinations and returns error messages indicating the presence of invalid operators.Incomplete Expression Error: This validation checks for incomplete expressions, where an operation is missing an operand. It returns error messages indicating the specific location of the incomplete expression.Division by Zero: This validation detects division by zero errors in the expression. It checks for divisions where the divisor is zero and returns error messages indicating the division by zero.Invalid Function: This validation identifies errors related to invalid function calls. It checks for unsupported or invalid function names and returns error messages indicating the presence of an invalid function call.Missing Operand: This validation checks for missing operands in the expression. It detects expressions where an operation is missing one of its operands and returns error messages indicating the location of the missing operand.Invalid Number Format: This validation identifies errors related to invalid number formats in the expression. It checks for numbers with incorrect decimal formats and returns error messages indicating the presence of invalid number formats.Invalid Variable: This validation detects errors related to unsupported or invalid variable names in the expression. It checks for variables with unsupported characters and returns error messages indicating the presence of an unsupported variable.These supported validations help ensure that the expression provided to the calculator is well-formed and prevent errors during the evaluation process.Unit TestsThetest_calculator.pyfile contains unit tests for theCalculatorclass. You can run these tests to ensure that the calculator functions correctly.To run the unit tests, execute the following command in the terminal:python -m unittest test_calculator.pyThe test cases cover various scenarios, including arithmetic operations, evaluation of expressions, unary operators, and trigonometric functions.