-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.py
99 lines (82 loc) · 2.14 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
94
95
96
97
98
# 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
# Exponentiation Function
# a -- base
# b -- power
def exp(a, b):
return a ** b
=======
#Mod function
#a -- dividend
#b -- divisor
def mod(a,b):
return a % b
>>>>>>> 98c358f2e3b9d05a2f015bbae0382a7e8b77c5bc
# -------------------------------------------------------- #
# -------------------------------------------------------- #
# -- 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 "Exponentiation: ", exp(a, b)
=======
elif (op == "%"):
print "Mod: ", mod(a, b)
>>>>>>> 98c358f2e3b9d05a2f015bbae0382a7e8b77c5bc
else:
print "Invalid operation..."
q = raw_input("Quit? [y/n] ")
if (q == "y" or q == "Y"):
break
# -------------------------------------------------------- #