-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlecturer.py
345 lines (339 loc) · 15.4 KB
/
lecturer.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
def add_question_answers(username):
try:
questions_and_answers = []
print("Subjects:")
with open("texts/topics.txt", "r") as file:
subjects = set()
topics = {}
for line in file:
topic, subject = line.strip().split("@")
if subject not in subjects:
subjects.add(subject)
topics[subject] = [topic]
else:
topics[subject].append(topic)
print("Available subjects:")
for i, subject in enumerate(sorted(list(subjects)), 1):
print(f"{i}. {subject}")
subject_index = int(input("Select a subject (enter the number): ")) - 1
selected_subject = sorted(list(subjects))[subject_index]
print(f"Topics for {selected_subject}:")
for i, topic in enumerate(topics[selected_subject], 1):
print(f"{i}. {topic}")
topic_index = int(input("Select a topic (enter the number): ")) - 1
selected_topic = topics[selected_subject][topic_index]
while True:
section = input(
"Select a section (A for multiple choice, B for subjective): "
).upper()
if section == "A":
question = input("Enter a question: ")
answer = input("Enter the correct answer: ")
option1 = input("Enter option 1: ")
option2 = input("Enter option 2: ")
option3 = input("Enter option 3: ")
option4 = input("Enter option 4: ")
questions_and_answers.append(
(
f"{selected_topic}@{selected_subject}, Section_A, {question}, {answer}, {option1}, {option2}, {option3}, {option4}"
)
)
elif section == "B":
question = input("Enter a question: ")
answer = input("Enter the answer: ")
questions_and_answers.append(
(f"{selected_topic}@{selected_subject}, Section_B, {question}, {answer}")
)
else:
print("Invalid section. Please try again.")
continue
print("Question and answer have been recorded successfully!")
add_another = input("Do you want to add another question and answer? (y/n): ")
if add_another.lower() == "n":
break
with open("texts/questions.txt", "a") as file:
for question in questions_and_answers:
file.write(question + "\n")
return True
except:
return False
def edit_question_answers(username):
try:
questions_and_answers = []
with open("texts/questions.txt", "r") as file:
for line in file:
line = line.strip()
parts = line.split(", ")
topic_subject = parts[0]
section = parts[1]
question = parts[2]
if section == "Section_A":
answer = parts[3]
options = parts[4:]
questions_and_answers.append(
(topic_subject, section, question, answer, options)
)
elif section == "Section_B":
answer = parts[3]
questions_and_answers.append((topic_subject, section, question, answer))
print("Available questions:")
for i, (topic_subject, section, question, *args) in enumerate(
questions_and_answers, 1
):
print(f"{i}. {topic_subject} - {question}")
question_index = int(input("Select a question to edit (enter the number): ")) - 1
topic_subject, section, question, *args = questions_and_answers[question_index]
if section == "Section_A":
answer, options = args
print(f"Current question: {question}")
print(f"Current answer: {answer}")
print("Current options:")
for i, option in enumerate(options, 1):
print(f"{i}. {option}")
new_question = input("Enter a new question (or press enter to keep the same): ")
if new_question:
question = new_question
new_answer = input("Enter a new answer (or press enter to keep the same): ")
if new_answer:
answer = new_answer
for i in range(4):
new_option = input(
f"Enter a new option {i+1} (or press enter to keep the same): "
)
if new_option:
options[i] = new_option
questions_and_answers[question_index] = (
topic_subject,
section,
question,
answer,
options,
)
elif section == "Section_B":
answer = args[0]
print(f"Current question: {question}")
print(f"Current answer: {answer}")
new_question = input("Enter a new question (or press enter to keep the same): ")
if new_question:
question = new_question
new_answer = input("Enter a new answer (or press enter to keep the same): ")
if new_answer:
answer = new_answer
questions_and_answers[question_index] = (
topic_subject,
section,
question,
answer,
)
with open("texts/questions.txt", "w") as file:
for topic_subject, section, question, *args in questions_and_answers:
if section == "Section_A":
answer, options = args
file.write(
f"{topic_subject}, {section}, {question}, {answer}, {', '.join(options)}\n"
)
elif section == "Section_B":
answer = args[0]
file.write(f"{topic_subject}, {section}, {question}, {answer}\n")
print("Questions and answers recorded successfully!")
return True
except:
return False
def view_question_answers(username):
try:
questions_and_answers = {}
with open("texts/questions.txt", "r") as file:
for line in file:
line = line.strip()
parts = line.split(", ")
topic_subject = parts[0]
section = parts[1]
question = parts[2]
if section == "Section_A":
answer = parts[3]
options = parts[4:]
if topic_subject not in questions_and_answers:
questions_and_answers[topic_subject] = [
(section, question, answer, options)
]
else:
questions_and_answers[topic_subject].append(
(section, question, answer, options)
)
elif section == "Section_B":
answer = parts[3]
if topic_subject not in questions_and_answers:
questions_and_answers[topic_subject] = [(section, question, answer)]
else:
questions_and_answers[topic_subject].append(
(section, question, answer)
)
print("Subjects:")
with open("texts/topics.txt", "r") as file:
subjects = set()
topics = {}
for line in file:
topic, subject = line.strip().split("@")
if subject not in subjects:
subjects.add(subject)
topics[subject] = [topic]
else:
topics[subject].append(topic)
while True:
print("Available subjects:")
for i, subject in enumerate(sorted(list(subjects)), 1):
print(f"{i}. {subject}")
subject_index = input("Select a subject (enter the number), or 'q' to quit: ")
if subject_index.lower() == "q":
break
try:
subject_index = int(subject_index) - 1
selected_subject = sorted(list(subjects))[subject_index]
except (ValueError, IndexError):
print("Invalid subject index. Please try again.")
continue
print(f"Topics for {selected_subject}:")
for i, topic in enumerate(topics[selected_subject], 1):
print(f"{i}. {topic}")
topic_index = input("Select a topic (enter the number), or 'q' to quit: ")
if topic_index.lower() == "q":
break
try:
topic_index = int(topic_index) - 1
selected_topic = topics[selected_subject][topic_index]
except (ValueError, IndexError):
print("Invalid topic index. Please try again.")
continue
if selected_topic + "@" + selected_subject in questions_and_answers:
print(f"Questions for {selected_topic}:")
for i, (section, question, *args) in enumerate(
questions_and_answers[selected_topic + "@" + selected_subject], 1
):
if section == "Section_A":
answer, options = args
print(f"{i}. {question} - {answer} (Options: {', '.join(options)})")
elif section == "Section_B":
answer = args[0]
print(f"{i}. {question} - {answer}")
else:
print(f"No questions for {selected_topic}")
except:
return False
def delete_question_answers(username):
try:
questions_and_answers = {}
with open("texts/questions.txt", "r") as file:
for line in file:
line = line.strip()
parts = line.split(", ")
topic_subject = parts[0]
section = parts[1]
question = parts[2]
if section == "Section_A":
answer = parts[3]
options = parts[4:]
if topic_subject not in questions_and_answers:
questions_and_answers[topic_subject] = [
(section, question, answer, options)
]
else:
questions_and_answers[topic_subject].append(
(section, question, answer, options)
)
elif section == "Section_B":
answer = parts[3]
if topic_subject not in questions_and_answers:
questions_and_answers[topic_subject] = [(section, question, answer)]
else:
questions_and_answers[topic_subject].append(
(section, question, answer)
)
print("Subjects:")
with open("texts/topics.txt", "r") as file:
subjects = set()
topics = {}
for line in file:
topic, subject = line.strip().split("@")
if subject not in subjects:
subjects.add(subject)
topics[subject] = [topic]
else:
topics[subject].append(topic)
while True:
print("Available subjects:")
for i, subject in enumerate(sorted(list(subjects)), 1):
print(f"{i}. {subject}")
subject_index = input("Select a subject (enter the number), or 'q' to quit: ")
if subject_index.lower() == "q":
break
try:
subject_index = int(subject_index) - 1
selected_subject = sorted(list(subjects))[subject_index]
except (ValueError, IndexError):
print("Invalid subject index. Please try again.")
continue
print(f"Topics for {selected_subject}:")
for i, topic in enumerate(topics[selected_subject], 1):
print(f"{i}. {topic}")
topic_index = input("Select a topic (enter the number), or 'q' to quit: ")
if topic_index.lower() == "q":
break
try:
topic_index = int(topic_index) - 1
selected_topic = topics[selected_subject][topic_index]
except (ValueError, IndexError):
print("Invalid topic index. Please try again.")
continue
if selected_topic + "@" + selected_subject in questions_and_answers:
print(f"Questions for {selected_topic}:")
for i, (section, question, *args) in enumerate(
questions_and_answers[selected_topic + "@" + selected_subject], 1
):
if section == "Section_A":
answer, options = args
print(f"{i}. {question} - {answer} (Options: {', '.join(options)})")
elif section == "Section_B":
answer = args[0]
print(f"{i}. {question} - {answer}")
while True:
delete_index = input(
"Select a question to delete (enter the number), or 'q' to quit: "
)
if delete_index.lower() == "q":
break
try:
delete_index = int(delete_index) - 1
section_to_delete, question_to_delete, *args_to_delete = (
questions_and_answers[
selected_topic + "@" + selected_subject
].pop(delete_index)
)
if section_to_delete == "Section_A":
answer_to_delete, options_to_delete = args_to_delete
print(
f"Deleted question: {question_to_delete} - {answer_to_delete} (Options: {', '.join(options_to_delete)})"
)
elif section_to_delete == "Section_B":
answer_to_delete = args_to_delete[0]
print(
f"Deleted question: {question_to_delete} - {answer_to_delete}"
)
except (ValueError, IndexError):
print("Invalid question index. Please try again.")
continue
with open("texts/questions.txt", "w") as file:
for topic, questions in questions_and_answers.items():
for section, question, *args in questions:
if section == "Section_A":
answer, options = args
file.write(
f"{topic}, {section}, {question}, {answer}, {', '.join(options)}\n"
)
elif section == "Section_B":
answer = args[0]
file.write(f"{topic}, {section}, {question}, {answer}\n")
print("Questions updated successfully.")
else:
print(f"No questions for {selected_topic}")
except:
return False