Python class for basic math operations.
Package calculator
contains Python class Calculator
that performs basic mathematical operations, including:
- addition;
- subtraction;
- scalar multiplication;
- division;
- exponentiation;
- taking square root and n-th root.
Class attributes:
.result
-- contains a numeric value of current result. Initial default value is 0.
Class methods:
.add()
,.subtract()
,.multiply_by()
,.divide_by()
,.exponentiate()
,.take_n_root()
,.sqrt()
-- These methods perform mathematical operations (addition, subtraction, scalar multiplication, division, exponentiation, taking n-th root, and taking square root respectively) on numeric value of.result
(attribute) and number provided by the user and saves the result as.result
..reset()
-- This method resets the.result
to 0 (default) or other user defined value.
Install from PyPi:
pip install calculator_vg
Install from GitHub:
pip install git+https://github.com/GegznaV/calculator-py.git
Get Docker image from Docker Hub with this package installed:
docker pull gegznav/calculator-py
>>> from calculator.calculator import Calculator
>>> calculator = Calculator()
>>> calculator.reset(to=35)
>>> calculator.result
35.0
>>> calculator.reset()
>>> calculator.result
0.0
>>> calculator.subtract(10)
>>> calculator.result
-10.0
>>> calculator.add(46)
>>> calculator.take_n_root(n=2)
>>> calculator.result
6.0
>>> calculator.reset()
>>> calculator.result
0.0
GitHub repo (with continuous integration) that hosts the project:
This project is licensed under the terms of the MIT license.
Vilmantas Gėgžna