Calculator in Python using tkinter for GUI.
Emulates an old-school handheld calculator, or the standard Microsoft calculator app.
calc.py
is our GUIcalc_func.py
contains our calculation functionstest_calc_func.py
contains unit tests forcalc_func.py
calculate(expr_list)
accepts a list of strings containing numbers and operators.
Returns the result of calculating the expression as an int
or float
.
Consider the following key presses (from left to right):
Key Presses calculate()
=========== ===========
7 + 3 / 2 x 3 =
^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | |
| | | | | | | Entry "15", Label "5 x 3 ="
| | | | | | Entry "3", Label "5 x" calculate(['5', 'x', '3']) => 15
| | | | | Entry "5", Label "5 x"
| | | | Entry "2", Label "10 /" calculate(['10', '/', '2']) => 5
| | | Entry "10", Label "10 /"
| | Entry "3", Label "7 +" calculate(['7', '+', '3']) => 10
| Entry "7", Label "7 +"
Entry "7", Label ""
7
+ 3
----
10
/ 2
----
5
x 3
====
15