Welcome to the Simple Calculator (CLI) page.
This page contains a brief description and implementation instructions for the project.
Project Description
A basic calculator for arithmetic operations. The program presents a menu (add, subtract, multiply, divide), asks the user to select an operation, and input two numbers. It then performs the operation and displays the result.
Project Requirements
Python 3.x (no external libraries; optional tkinter
if building a GUI).
How to Run the Project
- Write a script (e.g.
calculator.py
) defining functions for each operation (add, sub, etc.) and prompting the user with options. - Run it:
python calculator.py
. - Follow the menu (e.g. “1. Add 2. Subtract...”), enter two numbers, and see the result.
Key Concepts Learned
- Functions: Defining
add()
,subtract()
, etc., to encapsulate operations. - Conditional Logic: Using
if
/elif
to choose the correct function based on user input. - User Input and Output: Reading numbers and printing results.
- Error Handling: Checking for division by zero or invalid menu choices.
Possible Extensions
- Add more operations (exponentiation, modulo).
- Implement a looping menu to perform multiple calculations without restarting.
- Build a GUI with Tkinter, as GfG shows in the GUI section.
- Log calculation history to a file.