A simple, modular command-line calculator built with Python. It performs the four basic arithmetic operations (addition, subtraction, multiplication and division) on numbers entered by the user. The code is split into small, single-purpose modules, which makes it easy to read, test and extend.
- Features
- Project Structure
- Requirements
- Installation
- Usage
- Example Output
- How It Works
- Future Improvements
- Contributing
- Author
- Addition, subtraction, multiplication and division
- Works with integers and decimal numbers
- Takes input interactively from the user
- Clean modular design (logic, input handling and entry point are separated)
- No external libraries required
Simple_Calculator/
├── main.py # Entry point of the application
├── calculator.py # Calculator flow and user interface
├── math_ops.py # Arithmetic functions (add, subtract, multiply, divide)
├── user_input.py # Functions for reading and validating user input
├── requirements.txt # Project dependencies
└── README.md # Project documentation
- Python 3.8 or higher
- No third-party packages (the project uses only the Python standard library)
Check your Python version:
python --version-
Clone the repository
git clone https://github.com/faizanjutt473/Simple_Calculator.git
-
Move into the project folder
cd Simple_Calculator -
(Optional) Install dependencies
pip install -r requirements.txt
The project has no external dependencies, so this step is optional.
Run the application from the project folder:
python main.pyThen follow the on-screen prompts: enter the numbers and choose the operation you want to perform.
Enter first number: 12
Enter second number: 4
Choose operation (+, -, *, /): /
Result: 12 / 4 = 3.0
The exact prompts may differ slightly depending on the version of the code.
| Module | Responsibility |
|---|---|
main.py |
Starts the program |
calculator.py |
Connects user input with the math operations and shows the result |
math_ops.py |
Contains the pure arithmetic functions |
user_input.py |
Collects input from the user |
Keeping the math logic separate from input and output makes each part easy to test and reuse.
- Handle division by zero with a clear error message
- Validate non-numeric input with
try/except - Add more operations (power, modulus, square root)
- Let the user perform multiple calculations in a loop
- Add unit tests with
unittestorpytest - Build a GUI version using Tkinter
Contributions are welcome.
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -m "Add new feature") - Push to the branch (
git push origin feature/new-feature) - Open a Pull Request
Muhammad Faizan Farooq
- GitHub: faizanjutt473
- LinkedIn: Muhammad Faizan Farooq
If you found this project helpful, please consider giving it a star.