This project is a simple yet modular calculator built with Python. It has:
- A Tkinter-based GUI for interactive use
- A core logic module for calculations (easily reusable)
- A test suite using pytest
- A Jupyter notebook demo to show how to use the logic module
sprint2.project/
│
├── main_calculator.py # GUI code (Tkinter)
├── calculator_logic.py # Calculator logic (math operations)
├── test_calculator_logic.py # Unit tests using pytest
└── demo_calculator.ipynb # Notebook demo of logic usage
git clone https://github.com/TuringCollegeSubmissions/kvaiva-DS.v3.1.1.6/tree/main/sprint2.project
cd sprint2.projectpip install pytestpython main_calculator.pyThis will open a window with buttons for digits, arithmetic operations, clear (C), and square root (√).
The logic is separated in calculator_logic.py. You can use it in your own apps or scripts:
from calculator_logic import CalculatorLogic
calc = CalculatorLogic()
calc.input('8') # Enters number 8
calc.input('*') # Enters multiplication
calc.input('5') # Enters number 5
calc.input('=') # Calculates the result
print(calc.expression) # Output: '40'- Use
/between numbers before pressing√to get an nth root- Example:
27/3then√gives3.0(cube root of 27)
- Example:
- Press
Cto clear the current expression
All logic is covered with tests using pytest.
pytest test_calculator_logic.pyThis will run all tests and show you if any logic is broken.
Open demo_calculator.ipynb in Jupyter to see examples usage of CalculatorLogic.
jupyter notebook demo_calculator.ipynb