Skip to main content

Calculator for Python Mastery project

Project description

Part 5: Calculator

A project at Turing College

Installing the package

pip install calculatortbalse

Testing the package

After installation, you can launch the test suite from outside the package directory.

pytest calculatortbalse

Using the package

Initiate Calculator object

Calculator has internal memory, initiated at 0.0 by default. All methods can work with any float or int.

>>> calculator = Calculator()
>>> print(calculator)
Currently calculator reads: 0.0

However, you can pass in a number that will be stored in memory instead of 0.0.

>>> calculator = Calculator(2)
>>> print(calculator)
Currently calculator reads: 2.0

Reset internal memory

Similar to initiating a Calculator object, reset method can store the provided float in memory. Resets to 0.0 if no value is given.

>>> calculator.reset()
>>> print(calculator)
Currently calculator reads: 0.0

Perform addition, subtraction, multiplication and division

add, subtract, multiply, divide methods accept any float.

>>> calculator.reset()
>>> calculator.add(2)
Currently calculator reads: 2.0
>>> calculator.subtract(1)
Currently calculator reads: 1.0
>>> calculator.multiply(9)
Currently calculator reads: 9.0
>>> calculator.divide(3)
Currently calculator reads: 3.0

Take n-th degree root

root method takes the n-th degree root of the number curently stored in memory. Can only take roots of positive numbers.

>>> calculator.reset(8)
>>> calculator.root(3)
Currently calculator reads: 2.0

Chain multiple operations

add, subtract, multiply, divide, root methods can be chained together.

>>> calculator.reset()
>>> calculator.add(5).multiply(5).root(2)
Currently calculator reads: 5.0

Receive answer as float

The math operations will return the calculator object itself by default. You can terminate the operations chain with the answer method to receive the answer as float.

>>> calculator.reset()
>>> calculator.add(5).multiply(5).root(2).answer()
5.0

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

calculatortbalse-1.2.tar.gz (3.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page