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 details)

Uploaded Source

File details

Details for the file calculatortbalse-1.2.tar.gz.

File metadata

  • Download URL: calculatortbalse-1.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for calculatortbalse-1.2.tar.gz
Algorithm Hash digest
SHA256 096a858e3a55524a520448be7deef112e7b4785a6a56bededd7ae8acb1f7c57b
MD5 49fac75acd20625145a4833c15ba14e4
BLAKE2b-256 4ece975790b10d3f25d91e62757db68c0d630e08c5b30a0ea24600a250c273b2

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