Skip to main content

A simple Reporting program

Project description

Calculator

This 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 division
  • Support for complex expressions with multiple operators
  • Unary operators: positive and negative signs
  • Evaluation of expressions inside brackets
  • Trigonometric functions: sin, cos, tan, cosec, sec, and cot
  • Inverse trigonometric functions: asin, acos, atan

Getting Started

Install by command

pip install sk_calculator

Usage

To evaluate an arithmetic expression, create an instance of the Calculator class and call the evaluate method, passing the expression as a string parameter. The method will return the result of the evaluation.

Here's an example:

from sk_calculator import Calculator

# Create an instance of the Calculator class
calculator = Calculator()

# Evaluate an arithmetic expression
result = calculator.evaluate('2 + 3 * 4')
print(result)  # Output: 14

You can use the evaluate method to perform various calculations, including complex expressions and trigonometric functions.

Supported Operations

Arithmetic Operations

The calculator supports the following arithmetic operations:

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /
  • Power: ^
  • Module: %

Unary Operators

The calculator supports unary operators to represent positive and negative numbers:

  • Positive: +
  • Negative: -

Evaluation of Expressions

The 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: 20

Trigonometric Functions

The calculator provides trigonometric functions to calculate sine, cosine, tangent, cosecant, secant, and cotangent. The functions are case-insensitive.

  • Sine: sin
  • Cosine: cos
  • Tangent: tan
  • Cosecant: cosec
  • Secant: sec
  • Cotangent: cot

Here's an example:

result = calculator.evaluate('sin(45) + cos(30)')
print(result)  # Output: 1.573132185

Inverse Trigonometric Functions

The calculator also supports inverse trigonometric functions to calculate arcsine, arccosine, and arctangent. The functions are case-insensitive.

  • Arcsine: asin
  • Arccosine: acos
  • Arctangent: atan
  • ArcCosecant: acosec
  • ArcSecant: asec
  • ArcCotangent: acot

Here's an example:

result = calculator.evaluate('atan(1)')
print(result)  # Output: 45.0

Additional Functions

The calculator also supports the following additional functions:

  • Square Root: sqrt(x), where x is the number for which you want to calculate the square root. Example: sqrt(16) returns 4.

  • Absolute Value: abs(x), where x is the number for which you want to calculate the absolute value. Example: abs(-5) returns 5.

  • Exponential: exp(x), where x is the number for which you want to calculate the exponential value. Example: exp(2) returns 7.3890560989306495.

  • Logarithm: logx(y), where x is the base and y is the number for which you want to calculate the logarithm. Example: log10(100) returns 2. 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.945280495

Validations

The supported validations in your calculator.py program 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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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 Tests

The test_calculator.py file contains unit tests for the Calculator class. 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.py

The test cases cover various scenarios, including arithmetic operations, evaluation of expressions, unary operators, and trigonometric functions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sk_report_generator-1.0.101.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sk_report_generator-1.0.101-py3-none-any.whl (44.7 kB view details)

Uploaded Python 3

File details

Details for the file sk_report_generator-1.0.101.tar.gz.

File metadata

  • Download URL: sk_report_generator-1.0.101.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for sk_report_generator-1.0.101.tar.gz
Algorithm Hash digest
SHA256 deec8276f66d03fc39ce5331be32eef3eca03547691b5d8f7bc93481225596a8
MD5 672761b2697d959a0de497c58b28dd54
BLAKE2b-256 5c974cc0b0b4b7bf19b68d216f7fe81ce111812bf303e4628f5f7f0dd33e557b

See more details on using hashes here.

File details

Details for the file sk_report_generator-1.0.101-py3-none-any.whl.

File metadata

File hashes

Hashes for sk_report_generator-1.0.101-py3-none-any.whl
Algorithm Hash digest
SHA256 8492e3edc26b95d7217326ae07b3e3cd4c6c128150e8f4e63b593208514f6eb4
MD5 62bfd73e15ea689f18bd16c4c5d996dd
BLAKE2b-256 dc309b320173402778c2d05ed1458909ab3b376d21df41bc6ad895feedfd8f88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page