-
Notifications
You must be signed in to change notification settings - Fork 0
/
TridokuPython.py
193 lines (140 loc) · 4.57 KB
/
TridokuPython.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#representing tridoku in the format top,left,middle,right
vertices=[[[0,2,3,0],'T'],[[0,4,1,2],'L'],[[3,4,2,1],'M'],[[2,1,4,0],'R']]
#global variables for displaying entered values
global Apple
Apple="_"
global Mango
Mango="_"
global Pear
Pear="_"
global Grapes
Grapes="_"
#to display pramid
display=[["Apple"],[2,3,"Mango"],["Grapes",4,2,1,2],[4,1,2,3,1,4,"Pear"]]
side_tri=[]
#printing the pyramid
def printit():
indent=4
for i in range(len(display)):
print(' '*(indent-(i+1)),end='')
for j in display[i]:
print(j,'',end='')
print('\n')
print("\nApple: ",Apple,"\nMango: ",Mango,"\nPear: ",Pear,"\nGrapes: ",Grapes,"\n")
#Findig the values at the border of tridoku's three faces
def side_triangles(face):
new=[]
if face=="left":
for i in vertices:
if i[1]=='T' or i[1]=='L':
new.append(i[0][0])
new.append(i[0][1])
elif face=="right":
for i in vertices:
if i[1]=='T' or i[1]=='R':
new.append(i[0][0])
new.append(i[0][3])
elif face=="bottom":
for i in vertices:
if i[1]=='L' or i[1]=='R':
new.append(i[0][1])
new.append(i[0][3])
side_tri.append(new)
#check whether value for a blank is appropriate
def check_add(position,value,side1,side2=0):
if value in side_tri[side1]:
print("Sorry cannot add number")
return(False)
else:
if side2!=0:
if value in side_tri[side1]:
print("Sorry cannot add number")
return(False)
if value in vertices[position][0]:
print("Sorry cannot add element")
return(False)
print("Number added successfully")
return(True)
#add values if appropriate
def add():
print("\n\t1.Apple\n\t2.Mango\n\t3.Grapes\n\t4.Pear\nChoose which blank to fill")
pos1=input("Please enter the blank name : ")
pos2=int(input("Please enter any number : "))
global Apple
global Mango
global Pear
global Grapes
if pos1=="Apple":
chk=check_add(0,pos2,0,1)
if chk==True:
Apple=pos2
vertices[0][0][0]=pos2
elif pos1=="Mango":
chk=check_add(0,pos2,0)
if chk:
Mango=pos2
vertices[0][0][3]=pos2
elif pos1=="Grapes":
chk=check_add(1,pos2,1)
if (chk):
Grapes=pos2
vertices[1][0][0]=pos2
elif pos1=="Pear":
chk=check_add(3,pos2,0,2)
if (chk):
Pear=pos2
vertices[3][0][3]=pos2
side_tri.clear()
side_triangles("right")
side_triangles("left")
side_triangles("bottom")
#delete value from Trikodu
def delete():
global Apple
global Mango
global Pear
global Grapes
print("\n\t1.Apple\n\t2.Mango\n\t3.Grapes\n\t4.Pear\nChoose which blank to fill")
pos1=input("Please enter the blank name to delete it's value : ")
#if pos1=="apple"
if pos1=="Apple":
Apple="_"
vertices[0][0][0]=0
elif pos1=="Mango":
Mango="_"
vertices[0][0][3]=0
elif pos1=="Grapes":
Grapes="_"
vertices[1][0][0]=0
elif pos1=="Pear":
Pear="_"
vertices[3][0][3]=0
side_tri.clear()
side_triangles("right")
side_triangles("left")
side_triangles("bottom")
print("Number deleted Successfully")
#values of the three Faces/sides of the Tridoku
side_triangles("right")
side_triangles("left")
side_triangles("bottom")
#main block to call other functions
while True:
print("The Tridoku")
print("Let's fill the values named as fruit with right vlues to complete Tridoku\n\n")
printit()
print("Please select an option\n\t1.Add a Number\n\t2.Delete a Number")
val=input("Please enter a choice : ")
if val=="Add":
add()
elif val=="Delete":
delete()
else:
print("Please enter appropriate option\n")
if Apple!='_' and Grapes!='_' and Pear!='_' and Mango!='_':
printit()
print("\nThe Tridoku is Successfull solved ")
break
exit_val=input("Do you want to continue(y/n) : ")
if exit_val!="y" and exit_val!="Y":
break