Skip to content

About

A simple calculator in Python executes basic arithmetic operations like addition, subtraction, multiplication, and division using user-inputted numbers

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

Simple Calculator in Python

Python Type Dependencies

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.


Table of Contents


Features

  • 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

Project Structure

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

Requirements

  • Python 3.8 or higher
  • No third-party packages (the project uses only the Python standard library)

Check your Python version:

python --version

Installation

  1. Clone the repository

    git clone https://github.com/faizanjutt473/Simple_Calculator.git
  2. Move into the project folder

    cd Simple_Calculator
  3. (Optional) Install dependencies

    pip install -r requirements.txt

    The project has no external dependencies, so this step is optional.


Usage

Run the application from the project folder:

python main.py

Then follow the on-screen prompts: enter the numbers and choose the operation you want to perform.


Example Output

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.


How It Works

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.


Future Improvements

  • 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 unittest or pytest
  • Build a GUI version using Tkinter

Contributing

Contributions are welcome.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Commit your changes (git commit -m "Add new feature")
  4. Push to the branch (git push origin feature/new-feature)
  5. Open a Pull Request

Author

Muhammad Faizan Farooq


If you found this project helpful, please consider giving it a star.

About

A simple calculator in Python executes basic arithmetic operations like addition, subtraction, multiplication, and division using user-inputted numbers

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages