A basic command-line calculator built in Python that performs addition, subtraction, multiplication, and division. This was one of my early mini-projects while learning Python fundamentals.
Simple Calculator is a text-based tool that takes two numbers and an operator from the user, then returns the calculated result โ with built-in handling for invalid operators and division by zero.
- Supports all four basic operations:
+,-,*,/ - Handles division by zero gracefully with an error message
- Handles invalid operator input
- Works with decimal (float) numbers
The calculator() function:
- Prompts the user for a first number, an operator, and a second number
- Checks the operator and performs the matching calculation
- Prints the result โ or a friendly error message if something goes wrong
- Python 3.x installed on your machine
- Clone this repository
git clone https://github.com/Aafrakhan/Simple-Calculator.git
- Navigate to the project folder
cd Simple-Calculator - Run the script
python Simple_Calculator.py
- Follow the prompts to enter your numbers and operator
Welcome to Python Calculator
Enter first number: 2
Enter operator (+, -, *, /): -
Enter second number: 3
Result: -1.0
- Python โ functions, conditionals, and user input handling
This project helped me practice:
- Writing reusable functions
- Using
if/elif/elsechains to handle multiple cases - Type conversion with
float() - Basic error handling (division by zero, invalid input)
Aafra Khan GitHub: @Aafrakhan
โญ If you liked this project, feel free to star the repo!