Skip to main content

Beginner-friendly arithmetic — all five operations in one function call.

Project description

calcmate

Beginner-friendly arithmetic — all five operations in one function call.

PyPI version Python License: MIT


Why calcmate?

Learning Python means dealing with a lot of syntax before you get to the interesting parts. calcmate removes the friction from basic arithmetic so beginners can focus on concepts rather than operators.

Without calcmate:

a = 21
b = 7
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)

With calcmate:

from calcmate import calc

print(calc(21, 7))
{'add': 28, 'sub': 14, 'mul': 147, 'div': 3.0, 'floordiv': 3}

Installation

pip install calcmate

Requires Python 3.8 or higher. No dependencies.


Usage

All operations at once

from calcmate import calc

result = calc(15, 3)
print(result)
# {'add': 18, 'sub': 12, 'mul': 45, 'div': 5.0, 'floordiv': 5}

One operation at a time

calc(21, 7, '+')   # 28
calc(21, 7, '-')   # 14
calc(21, 7, '*')   # 147
calc(21, 7, '/')   # 3.0
calc(21, 7, '//')  # 3

Safe division

calc(10, 0)
# {'add': 10, 'sub': 10, 'mul': 0,
#  'div': 'Cannot divide by zero',
#  'floordiv': 'Cannot divide by zero'}

API reference

calc(a, b, op=None)

Parameter Type Description
a int or float First operand
b int or float Second operand
op str, optional Operator: '+', '-', '*', '/', '//'

Returns:

  • A single int, float, or str when op is provided
  • A dict with keys add, sub, mul, div, floordiv when op is omitted

Raises:

  • TypeError — if a or b are not numeric, or op is not a string
  • ValueError — if op is not one of the five supported operators

Contributing

git clone https://github.com/yourusername/calcmate.git
cd calcmate
pip install -e ".[dev]"
pytest

License

MIT — see LICENSE for details.

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

calcmate-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

calcmate-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file calcmate-0.1.0.tar.gz.

File metadata

  • Download URL: calcmate-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for calcmate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 67184eef231c3dd60af94885b63b7caf98af7ab7018c1db2cd7537441a3de70c
MD5 253d064395b137f046ab9d33a1443bcb
BLAKE2b-256 a7d3f51202e9506415718fb2748a7b10a96115c3567c9efe80b9cdaec0e822f1

See more details on using hashes here.

File details

Details for the file calcmate-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: calcmate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for calcmate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63d84cfe659c63dc09b70808c6d649e020df88d2d6d330fdf0dc9ca49b57970a
MD5 c1b22f4585a7d51f6533f44d4faaaf9f
BLAKE2b-256 2e7d00cc94528941efc006ae91441e1dc9d4212158480a488b2feb8ea14c64b2

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