This is a basic command-line calculator built in Python. It allows users to perform the four fundamental arithmetic operations: addition, subtraction, multiplication, and division.
- Add two numbers
- Subtract one number from another
- Multiply two numbers
- Divide one number by another (with division-by-zero handling)
The program asks the user to choose an operation (1–4), inputs two numbers, and then displays the result of the selected operation.
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y == 0:
return "Error: Division by zero"
return x / y
print("Simple Calculator")
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")