Skip to main content

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

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

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

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

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

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


Download files

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

Source Distribution

calculator_package_DOUG_HUNGWE-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file calculator_package_DOUG_HUNGWE-0.0.1.tar.gz.

File metadata

File hashes

Hashes for calculator_package_DOUG_HUNGWE-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8954d505029347c712fe8856ce2064731248ddd39228bdf916a5baba6234bae7
MD5 12ebc0c1231e747990badd51646a82e0
BLAKE2b-256 520be5b07536cd818998373aafed517cf3d4c8b10968f7aff827844ae7a58abf

See more details on using hashes here.

File details

Details for the file calculator_package_DOUG_HUNGWE-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for calculator_package_DOUG_HUNGWE-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 86293dc5f033b7431d7bd89e314a975d3a96c717050935485f21d872fae38917
MD5 e9be7cbe3b8373104b0f4f1837885649
BLAKE2b-256 8d1b01c2e90af69e8034b38bf27136fe9b2011a01e899ae578e4e7dea406fd1e

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