Skip to main content

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

MIT

Metadata

Release files for calculatormp 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for calculatormp 0.0.5
File Size Uploaded
calculatormp-0.0.5.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for calculatormp 0.0.5
File Interpreter ABI Platform
calculatormp-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / calculatormp-0.0.5.tar.gz

Download URL calculatormp-0.0.5.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
df862896243865e171520c6779772730e5f1f892f2ccd2aebbfee8feedd6754e
BLAKE2b-256 checksum
How to use checksums
b52028bca264fe35b498280a10ed7b1ddd0ff55e3e30e6ca84b4a764c3d24735
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release files / calculatormp-0.0.5-py3-none-any.whl

Download URL calculatormp-0.0.5-py3-none-any.whl
Size 3.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db062727fcaa91c8670c6c0390707046d9fe00588a6dfc3cd300954559ddc693
BLAKE2b-256 checksum
How to use checksums
ff2b8fc867957b025664e7c9515226d763870726b4c9f736bd292e6e5cf9e469
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.8

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page