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.1.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.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: calcmate-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 bd3136b547440bedc1b009f4268174a3197edf14a5e0edcecbe20126d7024357
MD5 aeb61bee7ea0f29b7b481a4f33be9c78
BLAKE2b-256 b4881d692bfe242ec93364e0c5ec482783e4a74531271b638cfc26d903422b1b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: calcmate-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed44db57129d3f5715bc3cf0ced92a295085d7566edd53b1029eac271153d74b
MD5 6d10143d209b35c7cf7682bac9136f08
BLAKE2b-256 f5c0fde2a65035290b33749a755d78ba34323acd9bf6de3e223a9f643ea8b11f

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