-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator Code.py
74 lines (59 loc) · 1.64 KB
/
Calculator Code.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Calculator -- a four function calculator commandline tool
import sys
# -------------------------------------------------------- #
# -- CALCULATOR FUNCTIONS -------------------------------- #
# -------------------------------------------------------- #
# Add function
# a -- addend
# b -- augend
def add(a, b):
return a + b
# Subtract function
# a -- minuend
# b -- subtrahend
def sub(a, b):
return a - b
# Multiply function
# a -- multiplicand
# b -- multiplier
def mult(a, b):
return a * b
# Divide function
# a -- dividend
# b -- divisor
def div(a, b):
return a / b
# -------------------------------------------------------- #
# -------------------------------------------------------- #
# -- MAIN FUNCTIONAILTY -- DO NOT EDIT ------------------- #
# -------------------------------------------------------- #
a = None
b = None
op = None
while (True):
# get input values
a = input("Enter the first argument: ")
op = input("Enter the operation: ")
b = input("Enter the second argument: ")
try:
a = int(a)
b = int(b)
except ValueError:
print ("Invalid number argument...")
op = None
# decide function
if (op != None):
if (op == "+"):
print ("Sum: ", add(a, b))
elif (op == "-"):
print ("Difference: ", sub(a, b))
elif (op == "*"):
print ("Product: ", mult(a, b))
elif (op == "/"):
print ("Quotient: ", div(a, b))
else:
print ("Invalid operation...")
q = input("Quit? [y/n]: ")
if (q == "y" or q == "Y"):
break
# -------------------------------------------------------- #