-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
35 lines (30 loc) · 861 Bytes
/
Calculator.py
File metadata and controls
35 lines (30 loc) · 861 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
35
def calculator():
print("Simple Python Calculator")
print("-------------------------")
# Get user inputs
try:
num1 = float(input("Enter first number: "))
operator = input("Enter operator (+, -, *, /): ")
num2 = float(input("Enter second number: "))
except ValueError:
print("Invalid number input!")
return
# Perform operation
if operator == '+':
result = num1 + num2
elif operator == '-':
result = num1 - num2
elif operator == '*':
result = num1 * num2
elif operator == '/':
if num2 == 0:
print("Error: Division by zero is not allowed!")
return
result = num1 / num2
else:
print("Invalid operator!")
return
# Display result
print(f"Result: {result}")
# Run the calculator
calculator()