Skip to content

codegnan-dm/calcmate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages