-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCalculator.py
More file actions
34 lines (30 loc) · 872 Bytes
/
SimpleCalculator.py
File metadata and controls
34 lines (30 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Simple Calculator in Python
# User input for operation
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
# Take user input for choice
choice = input("Enter choice (1/2/3/4): ")
# Input numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Perform the operation based on user choice
if choice == '1':
result = num1 + num2
print(f"{num1} + {num2} = {result}")
elif choice == '2':
result = num1 - num2
print(f"{num1} - {num2} = {result}")
elif choice == '3':
result = num1 * num2
print(f"{num1} * {num2} = {result}")
elif choice == '4':
if num2 == 0:
print("Error! Division by zero.")
else:
result = num1 / num2
print(f"{num1} / {num2} = {result}")
else:
print("Invalid input")