A simple calculator package
Project description
Calculator Class README
This README provides detailed information on how to use each method in the Calculator class, along with use cases and considerations.
Introduction
The Calculator class is designed to perform basic arithmetic operations on numbers. It includes methods for addition, subtraction, multiplication, division, and calculating the nth root of a number.
Installation
You can install the calculator package using pip. Open a terminal and run the following command:
pip install calculator
Class Methods
- add(self, first_number: float = 0, second_number: float = 0) -> float Adds two numbers and returns the sum.
Example: from calculator import Calculator
calculator = Calculator() result = calculator.add(3, 5) print(result) # Output: 8.0
- subtract(self, first_number: float = 0, second_number: float = 0) -> float Subtracts the second number from the first and returns the result.
Example: from calculator import Calculator
calculator = Calculator() result = calculator.subtract(10, 4) print(result) # Output: 6.0
- multiply(self, first_number: float = 0, second_number: float = 0) -> float Multiplies two numbers and returns the product.
Example from calculator import Calculator
calculator = Calculator() result = calculator.multiply(2, 3) print(result) # Output: 6.0
- divide(self, first_number: float = 0, second_number: float = 0) -> float Divides the first number by the second and returns the result. Raises: ValueError: If attempting to divide by zero.
Example from calculator import Calculator
calculator = Calculator() result = calculator.divide(8, 2) print(result) # Output: 4.0
- nth_root(self, first_number: float, n: int) -> float: calculates the nth root of a number.
from calculator import Calculator
calculator = Calculator() result_nth_root = calculator.nth_root(64, 2) # Square root of 64 = 8.0
Running Tests
To run the tests, make sure you have unittest installed:
pip install unittest
Then, run the tests using:
python -m unittest tests.test_calculator
Notes
**Ensure that the Calculator class is instantiated before using its methods. **Be cautious when using the divide method to avoid division by zero. **When using the nth_root method, be aware of the restriction on calculating the even root of a negative number. **Feel free to customize and integrate the Calculator class into your projects for basic arithmetic calculations.
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 calculator_package_DOUG_HUNGWE-0.0.1.tar.gz.
File metadata
- Download URL: calculator_package_DOUG_HUNGWE-0.0.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8954d505029347c712fe8856ce2064731248ddd39228bdf916a5baba6234bae7
|
|
| MD5 |
12ebc0c1231e747990badd51646a82e0
|
|
| BLAKE2b-256 |
520be5b07536cd818998373aafed517cf3d4c8b10968f7aff827844ae7a58abf
|
File details
Details for the file calculator_package_DOUG_HUNGWE-0.0.1-py3-none-any.whl.
File metadata
- Download URL: calculator_package_DOUG_HUNGWE-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86293dc5f033b7431d7bd89e314a975d3a96c717050935485f21d872fae38917
|
|
| MD5 |
e9be7cbe3b8373104b0f4f1837885649
|
|
| BLAKE2b-256 |
8d1b01c2e90af69e8034b38bf27136fe9b2011a01e899ae578e4e7dea406fd1e
|