A simple calculator module for arithmetic, scientific, and statistical operations
Project description
SimpleCalculatorPauLit
SimpleCalculatorPauLit is a Python-based calculator module designed to perform a variety of arithmetic, scientific, and statistical calculations. This module is designed to be simple to use and integrate into larger projects, providing robust and reusable functions for a wide range of mathematical operations.
Project was created for Component Based Software Engineering module in Kaunas University of Technology.
Features
- Basic Arithmetic Operations: Addition, subtraction multiplication, and division.
- Scientific Functions: Sine, cosine, tangent, logarithm (base 10), natural logarithm, and power functions.
- Statistical Functions: Mean, median, mode, standard deviation, and variance.
- Error Handling: Proper error handling for invalid operations such as division by zero or invalid inputs.
Installation
You can install SimpleCalculatorPauLit using pip:
pip install simplecalculatorpaulit
Usage
Basic Usage
Calculator class
>>> from simplecalculatorpaulit import Calculator
# Initialize the calculator with a starting number (default is 0)
>>> calc = Calculator(5)
# Perform basic arithmetic operations
>>> print(calc.add(10)) # Output: 15.0
>>> print(calc.subtract(3)) # Output: 12.0
>>> print(calc.multiply(2)) # Output: 24.0
>>> print(calc.divide(4)) # Output: 6.0
>>> print(calc.root(2)) # Output: 2.449489742783178
>>> print(calc.reset()) # Output: 5.0
Scientific Usage
ScientificCalculator class
>>> from simplecalculatorpaulit import ScientificCalculator
# Initialize the scientific calculator with a starting number (default is 0)
>>> sci_calc = ScientificCalculator(30)
# Perform scientific calculations
>>> print(sci_calc.sine()) # Output: 0.5 (approx)
>>> print(sci_calc.cosine()) # Output: 0.866 (approx)
>>> print(sci_calc.tangent()) # Output: 0.577 (approx)
>>> print(sci_calc.log()) # Output: 1.477 (approx)
>>> print(sci_calc.ln()) # Output: 3.401 (approx)
>>> print(sci_calc.power(3)) # Output: 27000.0
Scientific Usage
ScientificCalculator class
>>> from simplecalculatorpaulit import StatisticsCalculator
# Initialize the statistics calculator with a list of numbers
>>> stats_calc = StatisticsCalculator([1, 2, 2, 3, 4])
# Perform statistical calculations
>>> print(stats_calc.mean()) # Output: 2.4
>>> print(stats_calc.median()) # Output: 2.0
>>> print(stats_calc.mode()) # Output: [2]
>>> print(stats_calc.standard_deviation()) # Output: 1.019803902718557
>>> print(stats_calc.variance()) # Output: 1.04
API Reference
Calculator Class
- init(self, number=0): Initializes the calculator with an optional starting number.
- reset(self): Resets the calculator to the initial value.
- add(self, number_to_add): Adds a number to the current memory.
- subtract(self, number_to_subtract): Subtracts a number from the current memory.
- multiply(self, number_to_multiply): Multiplies the current memory by a number.
- divide(self, number_to_divide_by): Divides the current memory by a number.
- root(self, n_root_of_a_number): Takes the n-th root of the current memory.
ScientificCalculator Class (inherits from Calculator)
- sine(self): Calculates the sine of the current memory value.
- cosine(self): Calculates the cosine of the current memory value.
- tangent(self): Calculates the tangent of the current memory value.
- log(self, base=10): Calculates the logarithm of the current memory value to the specified base.
- ln(self): Calculates the natural logarithm of the current memory value.
- power(self, exponent): Raises the current memory value to the power of the given exponent.
StatisticsCalculator Class (inherits from Calculator)
- init(self, numbers): Initializes the calculator with a list of numbers for statistical calculations.
- mean(self): Calculates the mean of the list of numbers.
- median(self): Calculates the median of the list of numbers.
- mode(self): Calculates the mode of the list of numbers.
- standard_deviation(self): Calculates the standard deviation of the list of numbers.
- variance(self): Calculates the variance of the list of numbers.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any bugs, features, or documentation improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simplecalculatorpaulit-1.0.0.tar.gz.
File metadata
- Download URL: simplecalculatorpaulit-1.0.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28284228b136d5d988d979c8b767be58febf1ba4d36b7dd5b768083f796a34c1
|
|
| MD5 |
a974025f0e2e24674d4989d265c83fa0
|
|
| BLAKE2b-256 |
5759b03bfa5c79e39d8e39a04e059c559a2177618dcfa83dc3dc6c566e89940a
|
File details
Details for the file simplecalculatorpaulit-1.0.0-py3-none-any.whl.
File metadata
- Download URL: simplecalculatorpaulit-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56d5332d02827c84fa99e1ec59dfb15b8d5ccacf25d6394a09a2d915717e08a2
|
|
| MD5 |
9fd35efa423b1f942aa7747b2fca143f
|
|
| BLAKE2b-256 |
bbb1acbb14c58ec393821e4c3d81f34e37e3689b27ca4b80fcef985aa63e6d2b
|