-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathbasic calculator.py
44 lines (42 loc) · 1.36 KB
/
basic calculator.py
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
def add(a, b):
answer = a + b
print(str(a) + " + " + str( b) + " = " + str(answer) + "\n")
def sub(a, b):
answer = a - b
print(str(a) + " - " + str(b ) + " = " + str(answer) + "\n")
def mul(a, b):
answer = a*b
print(str(a) + " * " + str(b) + " = " + str(answer) + "\n")
def div(a, b):
answer = a / b
print(str(a) + " / " + str(b) + " = " + str(answer) + "\n")
while True:
print("A. Addition")
print("B. Subtraction")
print("C. Multiplication")
print("D. Division")
print("E. Exit")
choice = input("input your choice: ")
if choice == "a" or choice == "A":
print("Addition")
a = int(input("input first number: "))
b = int(input("input second number: "))
add(a, b)
elif choice == "b" or choice == "B":
print("Subtraction")
a = int(input("input first number:"))
b = int(input("input second number: "))
sub(a, b)
elif choice == "c" or choice == "C":
print("Multiplication")
a = int(input("input first number:"))
b = int(input("input second number: "))
mul(a, b)
elif choice == "d" or choice == "D":
print("Division" )
a = int(input("input first number:"))
b = int(input("input second number: "))
div(a, b)
elif choice == "e" or choice == "E":
print("program ended")
quit()