-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.py
93 lines (77 loc) · 2.04 KB
/
calc.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Copyright 2014 -- Levi Starrett
# for educational purposes only
#
# 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
#<<<<<<< HEAD
def exp(a,b):
return a ** b
#=======
#modulus fuction
def mod(a, b)
return a % b
#>>>>>>> d590381fbd0e8d0faaec009c1cbf7e1e39c286a7
# -------------------------------------------------------- #
# -------------------------------------------------------- #
# -- MAIN FUNCTIONAILTY -- DO NOT EDIT ------------------- #
# -------------------------------------------------------- #
a = None
b = None
op = None
while (True):
# get input values
a = raw_input("Enter the first argument: ")
op = raw_input("Enter the operation: ")
b = raw_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)
#<<<<<<< HEAD
elif (op == "**"):
print "Exponent: ", exp(a, b)
#=======
elif (op == "%"):
print "Modulus: ", mod(a, b)
#>>>>>>> d590381fbd0e8d0faaec009c1cbf7e1e39c286a7
else:
print "Invalid operation..."
q = raw_input("Quit? [y/n] ")
if (q == "y" or q == "Y"):
break
# -------------------------------------------------------- #