-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.py
56 lines (47 loc) · 1.84 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
# _______ _______ ___ _______ __ __ ___ _______ _______ _______ ______
# | || _ || | | || | | || | | _ || || || _ |
# | || |_| || | | || | | || | | |_| ||_ _|| _ || | ||
# | || || | | || |_| || | | | | | | | | || |_||_
# | _|| || |___ | _|| || |___ | | | | | |_| || __ |
# | |_ | _ || || |_ | || || _ | | | | || | | |
# |_______||__| |__||_______||_______||_______||_______||__| |__| |___| |_______||___| |_|
# John Omoluabi
# checklist
# ***********
# 1. define functions needed; add, subtract, multiply, divide
# 2. print options to user
# 3. ask for values
# 4. call functions
# 5. persist program until user wants to exit
def add(a,b):
return f"{a} + {b} = {int(a) + int(b)}"
def subtr(a,b):
return f"{a} - {b} = {int(a) - int(b)}"
def mult(a,b):
return f"{a} x {b} = {int(a) * int(b)}"
def divi(a,b):
return f"{a} / {b} = {int(a) / int(b)}"
print("A - Addition")
print("B - Subtraction")
print("C - Multiplication")
print("D - Division")
while True:
choice=input("What Operation would you like to do?(A-D)?")
choice=choice.lower()
match choice:
case "a":
a=input("first operand: ")
b=input("second operand: ")
print(add(a,b))
case "b":
a=input("first operand: ")
b=input("second operand: ")
print(subtr(a,b))
case "c":
a=input("first operand: ")
b=input("second operand: ")
print(mult(a,b))
case "d":
a=input("first operand: ")
b=input("second operand: ")
print(divi(a,b))