Contains Calculator Class used for performing basic arithmetic operations
Project description
Calculator package
Summary
The package contains a calculator class which is a python representation of a calculator. Calculator objects are used to perform the following operations:
-
Addition
-
Subtraction
-
Multiplication
-
Division
-
Taking n-th root of a positive number.
-
Reseting the memory
Installation
To install the package:
pip install tc-ds-2023-calculator
Using the package
To import the package:
from calculator import Calculator
Instantiating an object:
obj = Calculator(memory=0)
Memory stores the initial value which will later be manipulated. The variable is 0 by default but can be set to any other number of type int or float.
Operator behaviour and instance methods
Operators:
The class uses operator overloading for addition, subtraction, multiplication and division operations.
| + | Addition |
|---|---|
| - | Subtraction |
| * | Multiplication |
| / | Division |
These operations are done in a following manner:
object <operator> input
Example:
>>> obj = Calculator(2)
>>> obj
Calculator(2)
>>> obj + 2
>>> obj
Calculator(4)
>>> obj/2
>>> obj
Calculator(2)
>>> obj * 3
>>> obj
Calculator(6)
>>> obj / 2
>>> obj
Calculator(3)
Methods:
Calculator class provides following methods:
| .root(n=2) | Takes the n-th root of a positive number stored in the calculator memory. The n value must be an integer number. Only works with positive memory numbers even when n is odd. Takes the square root by default |
|---|---|
| .reset() | Sets the calculator memory to 0 |
| .get_num() | Returns calculator memory |
Example:
>>> obj = Calculator(4)
>>> obj.root()
>>> obj
Calculator(2)
>>> obj.reset()
>>> obj
Calculator(0)
>>> obj.get_num()
0
Testing
Install dependencies:
pip install -r requirements.txt
Test:
python3 -m unittest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tc-ds-2023-calculator-1.0.0.tar.gz.
File metadata
- Download URL: tc-ds-2023-calculator-1.0.0.tar.gz
- Upload date:
- Size: 13.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f9b9695e142e456a909b239c686c6298cb9fee2f6410b8769ea66ec86fa1250
|
|
| MD5 |
1a4498831c4e22e98e0d8c0e1ab2ff7f
|
|
| BLAKE2b-256 |
77be5a1abb49385fda52792f81c2e3a42194b208328a58f46169594acda3a21b
|
File details
Details for the file tc_ds_2023_calculator-1.0.0-py3-none-any.whl.
File metadata
- Download URL: tc_ds_2023_calculator-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e43c89fd245ea3790ac6aba019836ef1fa75b57681449f0c35b647d18e45a953
|
|
| MD5 |
a4787c298fb8e835531ab0114860d21b
|
|
| BLAKE2b-256 |
513d30e44c705d5fff7f98a9541bc66277c50117ab74a13f78ed70fd7889fd1e
|