-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.py
More file actions
25 lines (22 loc) · 707 Bytes
/
chat.py
File metadata and controls
25 lines (22 loc) · 707 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
def calculator(num1, num2, operator):
if operator == "+":
return num1 + num2
elif operator == "-":
return num1 - num2
elif operator == "/":
if num2 != 0:
return num1 / num2
else:
return "Error: Division by zero"
else:
return "Error: Invalid operator"
if __name__ == "__main__":
print("Simple Calculator")
try:
n1 = float(input("Enter first number: "))
op = input("Enter operator (+, -, *, /): "))
n2 = float(input("Enter second number: "))
result = calculator(n1, n2, op)
print(f"Result: {result}")
except ValueError:
print("Invalid input. Please enter numbers.")