A package containing basic arithmetic operations
Project description
Calculator
Calculator is a Python library that provides basic arithmetic operations.
Installation
You can install Calculator using pip:
python -m pip install calculatormp
Usage
Calculator provides add, subtract, multiply, divide, root and reset static methods of class Calculator. Each method (apart from reset) can take up to 2 arguments. If 1 argument is given, variable _memory (by default set to 0) is updated based on the chosen method, and its value is returned. If 2 arguments are given, variable _memory is set and returned based on the operation provided by the chosen method and 2 arguments. Giving 2 arguments disregards previous history of operations and automatically sets _memory to a new value. _memory can be manually set to 0 using reset() method.
from calculatormp.calculator import Calculator
# Addition - returns float stored in _memory + x
Calculator.add(5) # returns 5
# If optional argument y is provided, returns x + y
Calculator.add(5, 5) # returns 10
# Subtraction - returns float stored in _memory - x
Calculator.substract(5) # returns -5
# if optional argument y is provided, returns x - y
Calculator.substract(10, 5) # returns 5
# Multiplication - returns float stored in _memory * x
Calculator.add(5) # _memory = 5
Calculator.multiply(5) # returns 25
# if optional argument y is provided, returns x * y
Calculator.multiply(2, 10) # returns 20
# Division - returns float stored in _memory / x
Calculator.add(5) # _memory = 5
Calculator.divide(5) # returns 1
# if optional argument y is provided, returns x / y
Calculator.divide(10, 2) # returns 5
# Root - returns x-th root of float stored in _memory
Calculator.add(16) # _memory = 16
Calculator.root(2) # returns 4
# if optional argument y is provided, returns y-th root of x
Calculator.root(16, 2) # returns 4
# Reset - sets variable _memory to 0
Calculator.add(50) # returns 50
Calculator.add(5) # returns 55
Calculator.reset()
Calculator.add(1) # returns 1
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
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 calculatormp-0.0.5.tar.gz.
File metadata
- Download URL: calculatormp-0.0.5.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df862896243865e171520c6779772730e5f1f892f2ccd2aebbfee8feedd6754e
|
|
| MD5 |
02e2150fac5da4ef94fa6a46a1c638f9
|
|
| BLAKE2b-256 |
b52028bca264fe35b498280a10ed7b1ddd0ff55e3e30e6ca84b4a764c3d24735
|
File details
Details for the file calculatormp-0.0.5-py3-none-any.whl.
File metadata
- Download URL: calculatormp-0.0.5-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db062727fcaa91c8670c6c0390707046d9fe00588a6dfc3cd300954559ddc693
|
|
| MD5 |
74d2ab3d6ddc2f1de5a994acd5d0708a
|
|
| BLAKE2b-256 |
ff2b8fc867957b025664e7c9515226d763870726b4c9f736bd292e6e5cf9e469
|