Skip to main content

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.

Calculator App supports named session variables, letting you store a value once and reference it in as many expressions as you like without retyping the number. Variables live in a simple dictionary that persists for the entire session.

Setting a Variable

Type the variable name, an equals sign, and the value. There must be no arithmetic operators (+, -, *, /) on the left-hand side.
> x=5
Set x = 5

> total=100
Set total = 100

How Assignment Is Detected

In core.py, the input routing checks are ordered as follows:
# 1. Equation solver runs FIRST — any line with '=' and a letter is routed here
if '=' in line and re.search(r'[a-zA-Z]', line):
    result = solve_equation(line)
    print(result)
    continue

# 2. Numeric-only assignment — only reached if no letter is present in the line
if '=' in line and not any(op in line.split('=')[0] for op in ['+', '-', '*', '/']):
    name, value = line.split('=', 1)
    variables[name.strip()] = float(value.strip())
    print(f"Set {name.strip()} = {value.strip()}")
    continue
Because the equation solver check runs first and matches any line containing = and a letter, a letter-named assignment like x=5 is handled by solve_equation() rather than the variable assignment block. The variable assignment block is only reached for inputs where the left side contains no alphabetic characters at all (e.g., a purely numeric left side).
The equation solver intercepts x=5 and similar letter-named assignments before the variable assignment block can run. Variables are most reliably used by setting them through expressions that the solver processes, or by relying on the substitution that evaluator.py applies using whatever is already in the variables dict.

Using Variables in Expressions

Once a variable is stored in the variables dict, its name is substituted as a plain string into the expression before it reaches eval. This happens inside evaluator.py:
for name, value in variables.items():
    expr = expr.replace(name, str(value))
You can use variables anywhere an ordinary number would appear:
> x=5
Set x = 5

> x+3
= 8.0

> 2*x
= 10.0

> x**2
= 25.0

> x+x
= 10.0

Full Session Example

1

Assign a variable

> x=5
Set x = 5
2

Use it in calculations

> x+3
= 8.0
> 2*x
= 10.0
3

Reassign to update the value

> x=10
Set x = 10
> x+3
= 13.0

Storage

Variables are defined in variables.py as a plain module-level dictionary:
variables = {}
Both core.py and evaluator.py import this same object, so assignments made at the prompt are immediately visible to every subsequent evaluation.
Variables are stored as floats. Entering x=5 stores 5.0 internally, which is why expressions return float results (e.g., x+38.0). To update a variable, simply reassign it: x=10.
Variable substitution is a plain string replacement, so a variable named x will also match inside longer names if they share the same characters. Keep variable names short and unambiguous (single letters or short distinct strings) to avoid unexpected substitutions.

Build docs developers (and LLMs) love