Skip to main content

No project description provided

Project description

Module 1: Data Wrangling with Python

Sprint 1: Python Mastery

Part 5: Calculator

Install package from test-pypi

The following project consists of a calculator written with Python. It contains a Calculator class. This class has an internal memory, whose initial value is 0, and can perform a number of operations, which will modify the value in memory:

  • Add a value to the value stored in memory
  • Subtract a value to the value stored in memory
  • Multiply a value by the value stored in memory
  • Divide the value stored in memory by another value
  • Calculate the nth root of the value stored in memory
  • Reset the value stored in memory to 0

Since all operations (except resetting the value in memory) require an argument, two assertions have been included in order to make sure a valid argument is passed:

  • For all operations, the argument passed must be a number (either an int or a float). Otherwise, an AssertionError will be raised
  • Furthermore, to calculate the nth root of the value in memory, the argument passed cannot be 0. This is to prevent division by 0 (since the nth root of a number is equal to said number raised to the 1/nth power)

Here is a practical example of how the application works

# Package import
import Calculator
#An instance of Calculator is created.
# Value in memory is 0 (calculator.memory == 0)
calculator = Calculator()
# 10 is added to calculator.memory
calculator.add(10) # return 10
# 5 is subtracted to calculator.memory
calculator.subtract(5) # return 5
# 4 is multiplied by calculator.memory
calculator.multiply(4) # return 20
# calculator.memory is divided by 5
calculator.divide(5) # return 4
# the square root of calculator.memory is calculated
calculator.calculate_nth_root(2) # return 2
# calculator memory is set to 0
calculator.reset_memory()
# get memory
calculator.memory # return 0

In order to make sure the application works properly, unit tests have been written for all operations and assertions. unittest has been imported for this purpose.

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

calculator_package_gusaezg-0.0.2.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

calculator_package_gusaezg-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file calculator_package_gusaezg-0.0.2.tar.gz.

File metadata

File hashes

Hashes for calculator_package_gusaezg-0.0.2.tar.gz
Algorithm Hash digest
SHA256 beea9f8e10a5073a3bf6c4154c753f6d716ed5cbddca271141105bf26d51055b
MD5 8f23898495269598ec45f9cff664934a
BLAKE2b-256 5fc0dfd0aa12dc84141b7224b1a76d9f1441c840b505b56af5ae28cb094c29c2

See more details on using hashes here.

File details

Details for the file calculator_package_gusaezg-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for calculator_package_gusaezg-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b4680d637736ffef27e5245f29974fe8435a1ee978dc96476acc3a98e20d0057
MD5 de26de7a693157f976de031157d425c1
BLAKE2b-256 3b6c2c6ac05975565957768daa09e941dfecd63d9f69763e1d8c68a8a2df36bf

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