-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
31 lines (24 loc) · 649 Bytes
/
Copy pathcode.py
File metadata and controls
31 lines (24 loc) · 649 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
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b != 0:
return a / b
else:
return "Error! Division by zero."
num1 = float(input("Enter first number: "))
operator = input("Enter operator (+, -, *, /):")
num2 = float(input("Enter second number: "))
if operator == "+":
print("Result:", add(num1, num2))
elif operator == "-":
print("Result:", subtract(num1, num2))
elif operator == "*":
print("Result:", multiply(num1, num2))
elif operator == "/":
print("Result:", divide(num1, num2))
else:
print("Invalid operator!")