calcoolator


Namecalcoolator JSON
Version 0.0.8 PyPI version JSON
download
home_page
SummarySimple calculator project
upload_time2024-03-18 17:49:01
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords calculator newbie
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Cal-cool-ator 🔢

[![PyPI Version][pypi-badge]][pypi-link]  

This package contains a `Calculator` class written in 🐍Python capable of
performing simple tasks. Let's get to know it! 🏃🏻‍♂️💨  

**Table of contents:**

1. [Installation](#0️⃣-first-things-first)
2. [Setup](#1️⃣-import-and-setup)
3. [Class overview](#2️⃣-what-are-the-differences)
4. [Features](#3️⃣-methods-and-modifiers)
5. [Conclusions](#4️⃣-afterword)

---

## 0️⃣ First things first

In order for you to use the package, you will have to download it from PyPI,
using `pip` the Python package manager:

```sh
> pip install calcoolator
```

This shouldn't take long as it's a very basic, lightweight package and doesn't
require any dependencies. ***It just works out of the box!*** 🪄
Once the setup has finished, I reccomend you checking that it has been
correctly installed by running `pip list` (although this may result in a quite
lengthy output)
> 💡 A good idea would be *piping* it to `grep` or `FINDSTR` if you are on Windows:

```sh
# macOS / Linux / UNIX
$ pip list | grep calcoolator

# Windows
> pip list | FINDSTR calcoolator
```

The result should look somewhat like this:

```sh
calcoolator        x.x.x
```

Got it? Neat! Now we can move on. ✅

---

## 1️⃣ Import and setup

This package contains two main modules: `base_class` and `handler_class`, the
first having the parent `Calculator` and the second consisting of the child
`HandlerCalculator`. We will describe both in the next section. Right now,
let's focus on imports.  

☝🏻 Once you have the package, you can import it's classes by writing the following
lines at the beginning of your module:

```py
from calcoolator.base_class import Calculator
from calcoolator.handler_class import HandlerCalculator
```

and instantiating the class like this ⬇️

```py
calculator = Calculator()
handler_calculator = HandlerCalculator()
```

🤖 Okay, let's use our brand new calculator!

---

## 2️⃣ What are the differences?

Right, so both of the classes are basically the same, with the core difference
that `Calculator` will stop if it encounters an error while `HandlerCalculator`
will display a message in the console and keep going with whatever value had in
memory before it encountered the exception. *I couldn't decide which version to
implement* 🤷🏻 and I made both so you can choose the one that suits your needs!
If that sounds a bit confusing, let me give you an example:  

🧠 Suppose you want to chain some operations, and in the middle of your code, some
unsupported type slips into the arguments of the method you're using:

```py
base = Calculator()
base.add(5, 6)              # 11 -> (5 + 6)
base.subtract(9, 3)         # -1 -> (11 - 9 - 3)
base.divide(4, "oops!")     # ValueError -> The script stops
base.multiply(7)            # Not executed
```

```py
handler = HandlerCalculator()
handler.add(5, 6)           # 11 -> (5 + 6)
handler.subtract(9, 3)      # -1 -> (11 - 9 - 3)
handler.divide(4, "oops!")  # Displays the error and continues
handler.multiply(7)         # -7 -> (-1 * 7)
```

🌟 See the difference now? 🌟  
Well, that's it! Otherwise, both calculators work in exactly the same way

---

## 3️⃣ Methods and modifiers

The calculators come with the following methods and modifiers, which alter
the default behaviour of the method. The admitted arguments type are numbers,
either int or float or valid strings (e.g. `"42"`)  

| [Methods](#methods-default-behaviour) | [Keyword modifiers](#keyword-modifiers) |
| ----- | :-----: |
| [`add()`](#addargs-onlyfalse) | [`only`](#only) |
| [`subtract()`](#subtractargs-onlyfalse-reversefalse) | [`only`](#only) + [`reverse`](#reverse) |
| [`multiply()`](#multiplyargs-number-onlyfalse-factorfalse) | [`only`](#only) + [`factor`](#factor)|
| [`divide()`](#divideargs-onlyfalse-reversefalse) | [`only`](#only) + [`reverse`](#reverse)|
| [`nth_root()`](#nth_rootn1-value0) | None |
| [`power()`](#powerp1-value0) | None |
| [`reset()`](#resetvalue0) | None |
| [`get_memory()`](#get_memory) | None |
| [`screen()`](#screenmessage) | None |

---

### Methods default behaviour

#### `add(*args, only=False)`

Takes an arbitrary number of values and adds them including the memory:

```py
# calculator.memory = 10
calculator.add(5, 10)           # 25 -> (10 + 5 + 10)
```

#### `subtract(*args, only=False, reverse=False)`

Takes an arbitrary number of values and subtracts them in sequential order
taking the memory as first argument and continuing with the passed ones from
left to right:

```py
# calculator.memory = 10
calculator.subtract(5, 10)      # -5 -> (10 - 5 - 10)
```

#### `multiply(*args: Number, only=False, factor=False)`

Takes an arbitrary number of values and multiplies them together:

```py
# calculator.memory = 10
calculator.multiply(5, 10)      # 500 -> (10 * 5 * 10)
```

#### `divide(*args, only=False, reverse=False)`

Takes an arbitrary number of values and divides them in sequential order
taking the memory as first argument and continuing with the passed ones from
left to right:

```py
# calculator.memory = 10
calculator.divide(5, 10)        # 25 -> (10 + 5 + 10)
```

#### `nth_root(n=1, value=0)`

Calculates the (n)th root of the current memory if no second parameter is
present otherwise the (n)th root of the value specified as second argument:

```py
# calculator.memory = 8
calculator.nth_root(3)          # 2 -> (³√8)
calculator.nth_root(5, 243)     # 3 -> (⁵√243)
```

⚠️ **Please note:** I have incorporated a `NegativeRootError` exception in order to
disallow complex numbers to be thrown into the mix.

```py
# calculator.memory = -45
calculator.nth_root(3)          # NegativeRootError -> (³√-45 is not allowed)
```

> 📢 Shoutout to Vytautas Beinoravičius
> It was him who gave me the idea during an open session. Thank you! 💜

#### `power(p=1, value=0)`

Elevates the current memory to the p power, if a second parameter is specified,
then the base it's the value passed:

```py
# calculator.memory = 10
calculator.nth_root(3)          # 1000 -> (10³)
calculator.nth_root(6, 4)       # 4096 -> (4⁶)
```

#### `reset(value=0)`

Resets the calculator memory to 0 or the value you pass:

```py
# calculator.memory = 10
calculator.reset()              # 0
calculator.reset(123)           # 123
```

#### `get_memory()`

Returns the current memory value:

```py
# calculator.memory = 10
calculator.get_memory()         # 10
```

#### `screen(message="")`

Prints on stdout a pretty version of the calculator's memory

```py
# calculator.memory = 10
calculator.screen()
*------------------------------*
|                         10.0 |
*------------------------------*
calculator.screen("hello")
*------------------------------*
|            hello             |
*------------------------------*
```

---

### Keyword modifiers

You can mix them in the method that accepts them!

#### `only`

Available for `add`, `subtract`, `multiply` and `divide`  
Performs the operation **only** with the arguments, it ignores the memory value:

```py
# calculator.memory = 10
calculator.add(2, 5, only=True)         # 7 -> (2 + 5)
calculator.divide(8, 4, only=True)      # 2 -> (8 / 4)
```

#### `reverse`

Available for `subtract` and `divide`
Performs the operation **from right to left**:

```py
# calculator.memory = 10
calculator.subtract(2, 5, reverse=True)     # -7 -> (5 - 2 - 10)
calculator.reset(5)
calculator.divide(2, 10, reverse=True)      # 1 -> (10 / 2 / 5)
```

#### `factor`

Available just for `multiply`
Multiplies the memory value by each argument and then multiplies the results
together. Using `factor` will override `only`

```py
# calculator.memory = 5
calculator.multiply(2, 10)              # 500 -> (5*2) * (5*10)
```

*Phew!* That was quite a mouthful...

---

## 4️⃣ Afterword

**💪🏻 Now you know all the secrets of this Python package!**  
I hope you found this document informative / entertaining and helped you get the
maximum out of the classes the package contains.  
Anyway, if you ever forget something, you can always check the `help()`
function or read the `__doc__` of the precise method you need, you'll find
all this info there.  

### Thank you for your time and see you soon! 👋🏻

[![Github Badge][made]][git-hub]

<!-- Badges & links -->
[made]: https://img.shields.io/badge/made_with_%E2%9D%A4%EF%B8%8F-Berto_Polo-1A9CFF?logo=github&logoColor=FFFFFF
[git-hub]: https://github.com/berto-polo
[pypi-badge]: https://img.shields.io/pypi/v/calcoolator?logo=pypi&logoColor=FFFFFF&label=PyPI&color=303C75A
[pypi-link]: https://pypi.org/project/calcoolator/

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "calcoolator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "calculator,newbie",
    "author": "",
    "author_email": "Berto Polo <bertopolo@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/36/88/50d33fce9cc1b22d97a717a5471bf8e361115f8e814f894f69d8ef2e6c5b/calcoolator-0.0.8.tar.gz",
    "platform": null,
    "description": "# Cal-cool-ator \ud83d\udd22\n\n[![PyPI Version][pypi-badge]][pypi-link]  \n\nThis package contains a `Calculator` class written in \ud83d\udc0dPython capable of\nperforming simple tasks. Let's get to know it! \ud83c\udfc3\ud83c\udffb\u200d\u2642\ufe0f\ud83d\udca8  \n\n**Table of contents:**\n\n1. [Installation](#0\ufe0f\u20e3-first-things-first)\n2. [Setup](#1\ufe0f\u20e3-import-and-setup)\n3. [Class overview](#2\ufe0f\u20e3-what-are-the-differences)\n4. [Features](#3\ufe0f\u20e3-methods-and-modifiers)\n5. [Conclusions](#4\ufe0f\u20e3-afterword)\n\n---\n\n## 0\ufe0f\u20e3 First things first\n\nIn order for you to use the package, you will have to download it from PyPI,\nusing `pip` the Python package manager:\n\n```sh\n> pip install calcoolator\n```\n\nThis shouldn't take long as it's a very basic, lightweight package and doesn't\nrequire any dependencies. ***It just works out of the box!*** \ud83e\ude84\nOnce the setup has finished, I reccomend you checking that it has been\ncorrectly installed by running `pip list` (although this may result in a quite\nlengthy output)\n> \ud83d\udca1 A good idea would be *piping* it to `grep` or `FINDSTR` if you are on Windows:\n\n```sh\n# macOS / Linux / UNIX\n$ pip list | grep calcoolator\n\n# Windows\n> pip list | FINDSTR calcoolator\n```\n\nThe result should look somewhat like this:\n\n```sh\ncalcoolator        x.x.x\n```\n\nGot it? Neat! Now we can move on. \u2705\n\n---\n\n## 1\ufe0f\u20e3 Import and setup\n\nThis package contains two main modules: `base_class` and `handler_class`, the\nfirst having the parent `Calculator` and the second consisting of the child\n`HandlerCalculator`. We will describe both in the next section. Right now,\nlet's focus on imports.  \n\n\u261d\ud83c\udffb Once you have the package, you can import it's classes by writing the following\nlines at the beginning of your module:\n\n```py\nfrom calcoolator.base_class import Calculator\nfrom calcoolator.handler_class import HandlerCalculator\n```\n\nand instantiating the class like this \u2b07\ufe0f\n\n```py\ncalculator = Calculator()\nhandler_calculator = HandlerCalculator()\n```\n\n\ud83e\udd16 Okay, let's use our brand new calculator!\n\n---\n\n## 2\ufe0f\u20e3 What are the differences?\n\nRight, so both of the classes are basically the same, with the core difference\nthat `Calculator` will stop if it encounters an error while `HandlerCalculator`\nwill display a message in the console and keep going with whatever value had in\nmemory before it encountered the exception. *I couldn't decide which version to\nimplement* \ud83e\udd37\ud83c\udffb and I made both so you can choose the one that suits your needs!\nIf that sounds a bit confusing, let me give you an example:  \n\n\ud83e\udde0 Suppose you want to chain some operations, and in the middle of your code, some\nunsupported type slips into the arguments of the method you're using:\n\n```py\nbase = Calculator()\nbase.add(5, 6)              # 11 -> (5 + 6)\nbase.subtract(9, 3)         # -1 -> (11 - 9 - 3)\nbase.divide(4, \"oops!\")     # ValueError -> The script stops\nbase.multiply(7)            # Not executed\n```\n\n```py\nhandler = HandlerCalculator()\nhandler.add(5, 6)           # 11 -> (5 + 6)\nhandler.subtract(9, 3)      # -1 -> (11 - 9 - 3)\nhandler.divide(4, \"oops!\")  # Displays the error and continues\nhandler.multiply(7)         # -7 -> (-1 * 7)\n```\n\n\ud83c\udf1f See the difference now? \ud83c\udf1f  \nWell, that's it! Otherwise, both calculators work in exactly the same way\n\n---\n\n## 3\ufe0f\u20e3 Methods and modifiers\n\nThe calculators come with the following methods and modifiers, which alter\nthe default behaviour of the method. The admitted arguments type are numbers,\neither int or float or valid strings (e.g. `\"42\"`)  \n\n| [Methods](#methods-default-behaviour) | [Keyword modifiers](#keyword-modifiers) |\n| ----- | :-----: |\n| [`add()`](#addargs-onlyfalse) | [`only`](#only) |\n| [`subtract()`](#subtractargs-onlyfalse-reversefalse) | [`only`](#only) + [`reverse`](#reverse) |\n| [`multiply()`](#multiplyargs-number-onlyfalse-factorfalse) | [`only`](#only) + [`factor`](#factor)|\n| [`divide()`](#divideargs-onlyfalse-reversefalse) | [`only`](#only) + [`reverse`](#reverse)|\n| [`nth_root()`](#nth_rootn1-value0) | None |\n| [`power()`](#powerp1-value0) | None |\n| [`reset()`](#resetvalue0) | None |\n| [`get_memory()`](#get_memory) | None |\n| [`screen()`](#screenmessage) | None |\n\n---\n\n### Methods default behaviour\n\n#### `add(*args, only=False)`\n\nTakes an arbitrary number of values and adds them including the memory:\n\n```py\n# calculator.memory = 10\ncalculator.add(5, 10)           # 25 -> (10 + 5 + 10)\n```\n\n#### `subtract(*args, only=False, reverse=False)`\n\nTakes an arbitrary number of values and subtracts them in sequential order\ntaking the memory as first argument and continuing with the passed ones from\nleft to right:\n\n```py\n# calculator.memory = 10\ncalculator.subtract(5, 10)      # -5 -> (10 - 5 - 10)\n```\n\n#### `multiply(*args: Number, only=False, factor=False)`\n\nTakes an arbitrary number of values and multiplies them together:\n\n```py\n# calculator.memory = 10\ncalculator.multiply(5, 10)      # 500 -> (10 * 5 * 10)\n```\n\n#### `divide(*args, only=False, reverse=False)`\n\nTakes an arbitrary number of values and divides them in sequential order\ntaking the memory as first argument and continuing with the passed ones from\nleft to right:\n\n```py\n# calculator.memory = 10\ncalculator.divide(5, 10)        # 25 -> (10 + 5 + 10)\n```\n\n#### `nth_root(n=1, value=0)`\n\nCalculates the (n)th root of the current memory if no second parameter is\npresent otherwise the (n)th root of the value specified as second argument:\n\n```py\n# calculator.memory = 8\ncalculator.nth_root(3)          # 2 -> (\u00b3\u221a8)\ncalculator.nth_root(5, 243)     # 3 -> (\u2075\u221a243)\n```\n\n\u26a0\ufe0f **Please note:** I have incorporated a `NegativeRootError` exception in order to\ndisallow complex numbers to be thrown into the mix.\n\n```py\n# calculator.memory = -45\ncalculator.nth_root(3)          # NegativeRootError -> (\u00b3\u221a-45 is not allowed)\n```\n\n> \ud83d\udce2 Shoutout to Vytautas Beinoravi\u010dius\n> It was him who gave me the idea during an open session. Thank you! \ud83d\udc9c\n\n#### `power(p=1, value=0)`\n\nElevates the current memory to the p power, if a second parameter is specified,\nthen the base it's the value passed:\n\n```py\n# calculator.memory = 10\ncalculator.nth_root(3)          # 1000 -> (10\u00b3)\ncalculator.nth_root(6, 4)       # 4096 -> (4\u2076)\n```\n\n#### `reset(value=0)`\n\nResets the calculator memory to 0 or the value you pass:\n\n```py\n# calculator.memory = 10\ncalculator.reset()              # 0\ncalculator.reset(123)           # 123\n```\n\n#### `get_memory()`\n\nReturns the current memory value:\n\n```py\n# calculator.memory = 10\ncalculator.get_memory()         # 10\n```\n\n#### `screen(message=\"\")`\n\nPrints on stdout a pretty version of the calculator's memory\n\n```py\n# calculator.memory = 10\ncalculator.screen()\n*------------------------------*\n|                         10.0 |\n*------------------------------*\ncalculator.screen(\"hello\")\n*------------------------------*\n|            hello             |\n*------------------------------*\n```\n\n---\n\n### Keyword modifiers\n\nYou can mix them in the method that accepts them!\n\n#### `only`\n\nAvailable for `add`, `subtract`, `multiply` and `divide`  \nPerforms the operation **only** with the arguments, it ignores the memory value:\n\n```py\n# calculator.memory = 10\ncalculator.add(2, 5, only=True)         # 7 -> (2 + 5)\ncalculator.divide(8, 4, only=True)      # 2 -> (8 / 4)\n```\n\n#### `reverse`\n\nAvailable for `subtract` and `divide`\nPerforms the operation **from right to left**:\n\n```py\n# calculator.memory = 10\ncalculator.subtract(2, 5, reverse=True)     # -7 -> (5 - 2 - 10)\ncalculator.reset(5)\ncalculator.divide(2, 10, reverse=True)      # 1 -> (10 / 2 / 5)\n```\n\n#### `factor`\n\nAvailable just for `multiply`\nMultiplies the memory value by each argument and then multiplies the results\ntogether. Using `factor` will override `only`\n\n```py\n# calculator.memory = 5\ncalculator.multiply(2, 10)              # 500 -> (5*2) * (5*10)\n```\n\n*Phew!* That was quite a mouthful...\n\n---\n\n## 4\ufe0f\u20e3 Afterword\n\n**\ud83d\udcaa\ud83c\udffb Now you know all the secrets of this Python package!**  \nI hope you found this document informative / entertaining and helped you get the\nmaximum out of the classes the package contains.  \nAnyway, if you ever forget something, you can always check the `help()`\nfunction or read the `__doc__` of the precise method you need, you'll find\nall this info there.  \n\n### Thank you for your time and see you soon! \ud83d\udc4b\ud83c\udffb\n\n[![Github Badge][made]][git-hub]\n\n<!-- Badges & links -->\n[made]: https://img.shields.io/badge/made_with_%E2%9D%A4%EF%B8%8F-Berto_Polo-1A9CFF?logo=github&logoColor=FFFFFF\n[git-hub]: https://github.com/berto-polo\n[pypi-badge]: https://img.shields.io/pypi/v/calcoolator?logo=pypi&logoColor=FFFFFF&label=PyPI&color=303C75A\n[pypi-link]: https://pypi.org/project/calcoolator/\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Simple calculator project",
    "version": "0.0.8",
    "project_urls": {
        "Homepage": "https://github.com/berto-polo"
    },
    "split_keywords": [
        "calculator",
        "newbie"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b461d59d0b370594d88c521a012edf4d9f3abdc0921e3272e9b20cbb6988c407",
                "md5": "61e5694bd969d5bde49287199a44a77e",
                "sha256": "b5a5ead2e875d2da4f9b7242ed64cd9410e5b7baf1bdc3a7ff00a48a752e0b6a"
            },
            "downloads": -1,
            "filename": "calcoolator-0.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "61e5694bd969d5bde49287199a44a77e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12773,
            "upload_time": "2024-03-18T17:49:00",
            "upload_time_iso_8601": "2024-03-18T17:49:00.355656Z",
            "url": "https://files.pythonhosted.org/packages/b4/61/d59d0b370594d88c521a012edf4d9f3abdc0921e3272e9b20cbb6988c407/calcoolator-0.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "368850d33fce9cc1b22d97a717a5471bf8e361115f8e814f894f69d8ef2e6c5b",
                "md5": "97e9a7e62acc7636f9f26fd9fc149a77",
                "sha256": "41ee5b50831ecc2246b63fbfb268e40299edfa49d9c06b325967c1658172cf80"
            },
            "downloads": -1,
            "filename": "calcoolator-0.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "97e9a7e62acc7636f9f26fd9fc149a77",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17149,
            "upload_time": "2024-03-18T17:49:01",
            "upload_time_iso_8601": "2024-03-18T17:49:01.876594Z",
            "url": "https://files.pythonhosted.org/packages/36/88/50d33fce9cc1b22d97a717a5471bf8e361115f8e814f894f69d8ef2e6c5b/calcoolator-0.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-18 17:49:01",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "calcoolator"
}
        
Elapsed time: 0.23089s