This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Manager.py
192 lines (148 loc) · 5.33 KB
/
Manager.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
import random
from tkinter import *
def inputInt(content):
while True:
try:
choose = int(input(content))
return choose
except Exception as e:
print('enter again!')
def clickA(ques):
if int(ques.key) == 1:
print('bingo')
else:
print('right answer is {}'.format(ques.getKey()))
def clickB(ques):
if int(ques.key) == 2:
print('bingo')
else:
print('right answer is {}'.format(ques.getKey()))
def clickC(ques):
if int(ques.key) == 3:
print('bingo')
else:
print('right answer is {}'.format(ques.getKey()))
def clickD(ques):
if int(ques.key) == 4:
print('bingo')
else:
print('right answer is {}'.format(ques.getKey()))
class ManagerQuestion:
def __init__(self):
self.count = 0
self.list = []
def getNumberQuestion(self):
return self.count
def addQuestion(self, ques):
self.list.append(ques)
self.count += 1
def showQuestion(self):
for e in self.list:
print(e)
def getRank(self):
self.sort()
for i in range(self.count):
print("{} - {}/{}".format(i,
self.list[i].cRight, self.list[i].cWrong))
# def study(self):
# numberAnswered = 0
# ques = random.choice(self.list[0:int(self.count / 3)])
# # window.geometry("400x400")
# # window.minsize(400, 400)
# # window.maxsize(400, 400)
# # title game
# window.title = "==>Welcome to my Study<=="
# window.config(background='#fcb353')
# frame = Frame(window)
# frame.pack()
# question = Label(frame, text=ques.ques)
# question.pack()
# btnA = Button(frame, text=ques.ans1, command=lambda: clickA(ques))
# btnA.pack(side=TOP)
# btnB = Button(frame, text=ques.ans2, command=lambda: clickB(ques))
# btnB.pack(side=TOP)
# btnC = Button(frame, text=ques.ans3, command=lambda: clickC(ques))
# btnC.pack(side=TOP)
# btnD = Button(frame, text=ques.ans4, command=lambda: clickD(ques))
# btnD.pack(side=TOP)
# window.mainloop()
def write(self, source, path='out-studyed.txt'):
print("i'm storing...")
try:
with open(path, mode='w', encoding='utf8') as fo:
for e in source:
fo.write("{}\n".format(e.getInformation()))
return True
except Exception as e:
return False
def save(self, path='out-studyed.txt'):
print("i'm storing...")
try:
with open(path, mode='w', encoding='utf8') as fo:
self.sort()
for e in self.list:
fo.write("{}\n".format(e.getInformation()))
return True
except Exception as e:
return False
def sort(self):
self.list.sort(key=lambda e: (
int(e.cWrong), -int(e.cRight)), reverse=True)
def get(self, index=0):
return self.list[index]
def getQuestionMostWrongs(self, count=5):
mostWrongs = []
for i in range(count):
mostWrongs.append(self.get(i))
return mostWrongs
def getQuestionMostWrong(self):
self.sort()
return self.get(0)
def __str__(self):
return "managerQuestion have {} questions".format(str(self.count))
class Question:
def __init__(self, ques, ans1, ans2, ans3, ans4, key, cRight=0, cWrong=0):
self.ques = ques
self.ans1 = ans1
self.ans2 = ans2
self.ans3 = ans3
self.ans4 = ans4
self.key = key
self.cRight = cRight
self.cWrong = cWrong
def setKey(self):
while True:
try:
newKey = int(input("please enter new key 1 2 3 4: "))
if newKey > 4 or newKey < 1:
continue
self.key = newKey
break
except Exception as e:
pass
def check(self, e):
if (str(self.key).__eq__(str(e))):
return True
return False
def right(self):
self.cRight = int(self.cRight) + 1
def wrong(self):
self.cWrong = int(self.cWrong) + 1
def getQues(self):
return "{}/{} {}".format(self.cRight, self.cWrong, self.ques)
def getKey(self):
ans = ""
ans = self.ans1 if self.key == '1' else ans
ans = self.ans2 if self.key == '2' else ans
ans = self.ans3 if self.key == '3' else ans
ans = self.ans4 if self.key == '4' else ans
return "answer is {}. {}".format(self.key, ans)
def getInformation(self):
return str(self.ques) + "\n" + str(self.ans1) + "\n" + str(self.ans2) + "\n" + str(self.ans3) + "\n" + str(self.ans4) + "\n" + str(self.key) + "\n" + str(self.cRight) + "\n" + str(self.cWrong)
def __repr__(self):
return "{}\n{}\n{}\n{}\n{}\n{}\n".format(self.ques, self.ans1,
self.ans2, self.ans3,
self.ans4, self.key)
def __str__(self):
return "\nCau hoi la({}/{}): {}\n1. {}\n2. {}\n3. {}\n4. {}\n".format(self.cRight, self.cWrong,
self.ques, self.ans1, self.ans2, self.ans3, self.ans4)