Simple Calculator with Pyhton
🧮 Program Purpose
This Python program is a simple calculator that allows the user to:
✅ Choose an operation
✅ Enter two numbers
✅ See the calculated result
Supported operations:
- Addition
- Subtraction
- Multiplication
- Division
- Addition
- Subtraction
- Multiplication
- Division
- Division by Zero Protection
Python Code :
print("Select operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
choice = input("Enter your choice (1/2/3/4): ")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print("Result =", num1 + num2)
elif choice == '2':
print("Result =", num1 - num2)
elif choice == '3':
print("Result =", num1 * num2)
elif choice == '4':
if num2 != 0:
print("Result =", num1 / num2)
else:
print("Error: Cannot divide by zero!")
else:
print("Invalid choice")
Example Run
Select operation:
1. Addition
2. Subtraction
3. Multiplication
4. Division
Enter your choice (1/2/3/4): 4
Enter first number: 10
Enter second number: 2
Result = 5.0
Key Concepts Used
✔ print() → display text
✔ input() → read user input
✔ float() → convert to decimal number
✔ if / elif / else → decision making
✔ nested if → check division safety
Why This Program is Good for Beginners
✅ teaches user input
✅ introduces conditions
✅ shows error handling
✅ demonstrates arithmetic operations
Comments
Post a Comment