Skip to content

Repository files navigation

🧮 Python GUI Calculator

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

📦 Project Structure

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

🚀 Installation

Clone the repository

git clone https://github.com/TuringCollegeSubmissions/kvaiva-DS.v3.1.1.6/tree/main/sprint2.project
cd sprint2.project

Install dependencies

pip install pytest

🖥️ How to Run the Calculator (GUI)

python main_calculator.py

This will open a window with buttons for digits, arithmetic operations, clear (C), and square root ().


🧠 How the Logic Module Works

The logic is separated in calculator_logic.py. You can use it in your own apps or scripts:

Example:

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'

Special Features:

  • Use / between numbers before pressing to get an nth root
    • Example: 27/3 then gives 3.0 (cube root of 27)
  • Press C to clear the current expression

✅ Running Tests

All logic is covered with tests using pytest.

pytest test_calculator_logic.py

This will run all tests and show you if any logic is broken.


📓 Demo Notebook

Open demo_calculator.ipynb in Jupyter to see examples usage of CalculatorLogic.

jupyter notebook demo_calculator.ipynb

About

Python GUI Calculator

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages