Calculator App is a pure-Python, zero-dependency project, which makes it easy to clone, modify, and test locally. This guide walks through the development setup, the project structure, and the concrete patterns used to extend each layer of the application.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Seaus-tech/Calculator-App/llms.txt
Use this file to discover all available pages before exploring further.
The project is hosted on GitHub at https://github.com/Seaus-tech/Calculator-App. Open issues and pull requests there.
Development Setup
Clone the repository and install the package in editable mode. Editable mode (-e) means changes you make to the source files are reflected immediately without reinstalling.
calc-app entry point is available on your PATH and the calc_app package is importable in any Python script.
Requirements:
- Python ≥ 3.10 (the code uses
str | Noneunion syntax in return annotations) - No third-party dependencies — the standard library is sufficient
Project Structure
A brief recap of each module’s responsibility. For full detail on the evaluation pipeline, REPL dispatch, and public APIs, see the Architecture page.core.py
REPL loop and top-level command dispatch. Handles
quit, meme toggle, equation detection, variable assignment, and falls back to calc().evaluator.py
The
calc(expr) function. Runs the full transformation pipeline: NL parsing → fraction rewriting → caret conversion → variable substitution → sandboxed eval().parser.py
parse_natural_language(expr). Converts English phrases (squared, sqrt of, cubed) into valid Python math notation using re.sub.fractions.py
parse_fractions(expr). Rewrites a/b and mixed-number whole a/b literals to Fraction(numerator, denominator) constructor calls.solver.py
solve_equation(equation). Handles linear equations with algebraic coefficient extraction and falls back to integer brute-force search (−100,000 to 100,000) for other forms.meme.py
handle_meme(line, meme_mode). Returns humorous responses for specific expressions when meme mode is active; returns None otherwise.variables.py
The shared
variables dict. Populated at the REPL via name=value; consumed by calc() during variable substitution.app.py
Package entry point. Imports
main from core and calls it under if __name__ == "__main__".How to Add a New Feature
Identify the right module
Decide which layer owns your feature:
- New English phrase support →
parser.py(parse_natural_language) - New math function available in expressions →
evaluator.py(safe_dict) - New equation-solving strategy →
solver.py(solve_equation) - New easter egg →
meme.py(handle_meme) - New REPL command →
core.py(main)
Add the new logic
Make your change inside the identified module. The sections below show concrete patterns for the most common extension points. Keep changes focused — each module has a single responsibility, and cross-cutting changes are usually a sign that two separate modules should each receive a small update.
Add test cases in calc_tests.py
Append a
(expression, expected_result) tuple to the appropriate test function’s tests list. If your feature doesn’t fit an existing category, add a new test_your_feature() function following the same pattern and call it at the bottom of if __name__ == "__main__".Run the test suite
Verify that all existing tests still pass and your new cases produce A clean run ends with
✓:=== Test Complete === and no ✗ lines.How to Add a New Meme Easter Egg
Opencalc_app/meme.py. The handle_meme function checks the stripped input line against a series of if statements. Add a new block following the same pattern:
67 and 41 cases do), call calc() and interpolate the result:
How to Add a New Math Function
Math functions are whitelisted in thesafe_dict inside calc_app/evaluator.py. Adding a new function means importing it from math and adding an entry to the dict:
floor(3.7) or ceil(3.2) directly at the REPL and in expressions — no other changes are needed.
How to Add a New Natural Language Pattern
Opencalc_app/parser.py. Each pattern is a re.sub call that matches an English phrase and replaces it with valid Python math syntax. Add your pattern before the return statement:
test_natural_language() in calc_tests.py: