Skip to main content

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:

py -m pip install --index-url https://test.pypi.org/simple/ --no-deps 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

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

calculatormp-0.0.3.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

calculatormp-0.0.3-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file calculatormp-0.0.3.tar.gz.

File metadata

  • Download URL: calculatormp-0.0.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for calculatormp-0.0.3.tar.gz
Algorithm Hash digest
SHA256 54b3d7fe9ebffc7e93989988a3daae966b8e07cb44b081c67bd73893369bd2ac
MD5 8b231ec4d45808d406722bd197130cc7
BLAKE2b-256 2f78e9046945fb7a87c8ca958fea60f362995d8cc5eaa3aae193b74ca2063a3d

See more details on using hashes here.

File details

Details for the file calculatormp-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: calculatormp-0.0.3-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

Hashes for calculatormp-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 addf31efc9d572a4e19ef8ad7dd39d204808a7ac35d5e5ed44706d6376f81c78
MD5 f6ce80228fea6f08af61408974ccbe28
BLAKE2b-256 7088fc783874a4e0c37d9c48a5f9e4ec10499d911a871081b27f811b43b61b75

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