-
Notifications
You must be signed in to change notification settings - Fork 0
/
extra.py
46 lines (31 loc) · 845 Bytes
/
extra.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
from decimal import Decimal
# region Global Variables
ONEPLACE = Decimal(10) ** -1
TWOPLACES = Decimal(10) ** -2
THREEPLACES = Decimal(10) ** -3
rounding_num = THREEPLACES
separators = {
0: "--------------------",
1: "-Input--------------",
2: "-Output-------------",
3: "-Commands-----------"
}
if not __name__ == '__main__':
def separator(separator_index):
print("")
print(separators[separator_index])
print("")
def add(x, y, fp=rounding_num):
return Decimal(x + y).quantize(fp)
def sub(x, y, fp=rounding_num):
return Decimal(x - y).quantize(fp)
def mul(x, y, fp=rounding_num):
return Decimal(x * y).quantize(fp)
def div(x, y, fp=rounding_num):
try:
val = Decimal(x / y).quantize(fp)
except ZeroDivisionError:
val = 0
return val
def qnt(x, fp=rounding_num):
return Decimal(x).quantize(fp)