-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplecalculator.py
More file actions
44 lines (31 loc) · 870 Bytes
/
simplecalculator.py
File metadata and controls
44 lines (31 loc) · 870 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
36
37
38
39
40
41
42
43
44
# Simple calculator
def add(x, y):
return x + y
# subtract function
def subtract(x, y):
return x - y
# Multiplication function
def multiply(x, y):
return x * y
# divison function
def divide(x, y):
return x / y
print(" Select Operations")
print("1 Add")
print("2 Subtract")
print("3 Multiply")
print("4 Divide")
# take a choice from the user
choice = input("\nEnter Choice(1 / 2 /3 / 4)\n")
num1 = float(input("\nEnter first number\n"))
num2 = float(input("\nEnter second number\n"))
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1,"-",num2,"=", subtract(num1,num2))
elif choice == '3':
print(num1,"*",num2,"=", multiply(num1,num2))
elif choice == '4':
print(num1,"/",num2,"=", divide(num1,num2))
else:
print("\nInvalid input\n")