-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumtable.py
More file actions
65 lines (43 loc) · 1.5 KB
/
Copy pathnumtable.py
File metadata and controls
65 lines (43 loc) · 1.5 KB
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
from ansicodes import *
def equal(x, y, product):
return x == y
def falseFunc(x, y, product):
return False
def numTable(xmin, xmax, ymin, ymax, checkFunc=falseFunc):
xSize = len(str(xmax*ymax)) + 2
rowInvert = 0
colInvert = 0
PRINTSTR = "{{0:^{0}}}".format(xSize)
HEADSTRING = BOLDON + WHITEF + BLUEB + PRINTSTR + RESET
HEADSTRING2 = BLACKB + WHITEF + (" " * xSize) + RESET
BODYSTRING1 = BLACKB + WHITEF + PRINTSTR + RESET
BODYSTRING2 = WHITEB + BLACKF + PRINTSTR + RESET
BODYSTRING3 = BLACKB + REDF + BOLDON + PRINTSTR + RESET
BODYSTRING4 = WHITEB + REDF + BOLDON + PRINTSTR + RESET
for i in range(ymin-1, ymax+1):
if i == ymin-1:
print(HEADSTRING2, end="")
else:
print(HEADSTRING.format(i), end="")
print()
for i in range(xmin, xmax+1):
print(HEADSTRING.format(i), end="")
for j in range(ymin, ymax+1):
product = i * j
inv = rowInvert ^ colInvert
if checkFunc(i, j, product) == True:
if inv:
tmp = BODYSTRING3
else:
tmp = BODYSTRING4
else:
if inv:
tmp = BODYSTRING1
else:
tmp = BODYSTRING2
colInvert = not colInvert
print(tmp.format(product), end="")
print()
rowInvert = not rowInvert
colInvert = 0
print()