-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
434 lines (322 loc) · 16.8 KB
/
main.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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
from sys import exit
from os import startfile
from time import strftime
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "PAPER CONSOLE", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "VERSION - 1.0", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
date = strftime('%d %b %Y')
report_file = open(date + '.txt', 'w')
students_present = list()
students_absent = list()
class_list = list()
def create_class():
global class_list
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "CREATE CLASS", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
class_strength = -1
while class_strength <= 0:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
class_strength = int(input('{: ^9}|{}'.format("","ENTER CLASS STRENGTH: ")))
if class_strength <= 0:
print('{: ^9}|{}'.format("",f"ERROR: Invalid input!"))
while len(class_list) < class_strength:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
student_name = input('{: ^9}|{}'.format("","ENTER STUDENT NAME: ")).strip()
if student_name == "":
print('{: ^9}|{}'.format("","ERROR: Invalid input!"))
elif student_name not in class_list:
class_list.append(student_name)
print('{: ^9}|{}'.format("",f"SUCCESS: {student_name} added to class."))
else:
print('{: ^9}|{}'.format("","ERROR: Student exists!"))
write_class_data()
mark_attendance()
try:
data_file = open("My Class.txt", "r+")
test_string = data_file.readline()
except FileNotFoundError:
data_file = open("My Class.txt", "w+")
data_file.write("[UNAVAILABLE]\n")
data_file.flush()
data_file.seek(0)
test_string = data_file.readline()
def prepare_class_list():
global class_list
data_file.seek(0)
data_file.readline()
class_data = data_file.readlines()
for i in range(len(class_data)):
class_data[i] = class_data[i].replace('\n', '')
for i in class_data:
data = i.split('.')
if data[1] not in class_list:
class_list.append(data[1])
def write_class_data():
global class_list
class_list.sort()
data_file = open("My Class.txt", "w+")
data_file.seek(0)
if class_list != []:
data_file.write("[AVAILABLE]\n")
else:
data_file.write("[UNAVAILABLE]\n")
for i in range(len(class_list)):
data_file.write(f"{i+1}.{class_list[i]}\n")
data_file.flush()
def display_about():
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "PAPER CONSOLE", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "VERSION - 1.0", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "AUTHOR: SAURABH KUMAR", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
def edit_class():
global class_list
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "EDIT CLASS", ""))
print('{: ^9}|{:-^56}|{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","1. ADD STUDENT", ""))
print('{: ^9}|{:-^56}|{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","2. REMOVE STUDENT", ""))
print('{: ^9}|{:-^56}|{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","3. RENAME STUDENT", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","4. SHOW CLASS", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","0. SAVE CHANGES", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
while True:
correct_choice = None
while correct_choice not in [1, 2, 3, 4, 0]:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
choice = int(input('{: ^9}|{}'.format("","ENTER CHOICE[0: SAVE CHANGES]: ")))
if choice in [1, 2, 3, 4, 0]:
correct_choice = choice
else:
print("{: ^9}|{}".format("", "ERROR: Invalid input!"))
if choice == 1:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "ADD STUDENT", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
student_name = input("{: ^9}|{}".format("", "ENTER NAME: ")).strip()
if student_name.isalnum() == False:
print('{: ^9}|{}'.format("","ERROR: Invalid input!"))
elif student_name not in class_list:
class_list.append(student_name)
print('{: ^9}|{}'.format("",f"SUCCESS: {student_name} added to class."))
else:
print('{: ^9}|{}'.format("","ERROR: Student exists!"))
elif choice == 2:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "REMOVE STUDENT", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
student_roll = int(input("{: ^9}|{}".format("", "ENTER ROLL NUMBER: ")))
if 1 <= student_roll <= len(class_list):
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{}'.format("",class_list[student_roll - 1]))
verify = input('{: ^9}|{}'.format("","REMOVE STUDENT?[y: YES/ n: NO]: ")).strip()
if verify in ["y", "Y"]:
class_list.pop(student_roll - 1)
print('{: ^9}|{}'.format("",f"SUCCESS: Roll number {student_roll} removed from class."))
else:
print('{: ^9}|{}'.format("","ERROR: Roll number does not exist!"))
elif choice == 3:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "RENAME STUDENT", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
student_roll = int(input("{: ^9}|{}".format("", "ENTER ROLL NUMBER: ")))
if 0 < student_roll <= len(class_list):
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{}'.format("",class_list[student_roll - 1]))
new_name = input('{: ^9}|{}'.format("","NEW NAME: ")).strip()
if new_name not in class_list:
class_list[student_roll - 1] = new_name
print('{: ^9}|{}'.format("","SUCCESS: Student renamed."))
else:
print('{: ^9}|{}'.format("",f"ERROR: Roll number not found!"))
elif choice == 4:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "STUDENTS", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
for student in class_list:
print('{: ^9}|{: <56}|{: ^9}'.format("",f"{class_list.index(student) + 1}. {student}", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
elif choice == 0:
write_class_data()
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "CHANGES SAVED.", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
break
def save_data():
global report_file
global students_present
global students_absent
report_file.write('Date:' + date + '\n')
report_file.write('\nTOTAL STUDENTS: ' + str(len(class_list)) + '\n')
report_file.write('PRESENT: ' + str(len(students_present)) + '\n')
report_file.write('ABSENT: ' + str(len(students_absent)) + '\n')
report_file.write('\nPRESENT:\n')
if students_present != []:
for roll in students_present:
report_file.write(str(students_present.index(roll) + 1)
+ '.' + class_list[roll - 1] + '\n')
else:
report_file.write('None\n')
report_file.write('\nABSENT:\n')
if students_absent != []:
for roll in students_absent:
report_file.write(str(students_absent.index(roll) + 1)
+ '.' + class_list[roll - 1] + '\n')
else:
report_file.write('None\n')
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "ATTENDANCE SAVED.", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
report_file.close()
startfile(date + '.txt')
def edit_data():
global students_present
global students_absent
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "EDIT ATTENDANCE", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
verify = 1
while verify == 1:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
roll = int(input("{: ^9}|{}".format("", "ENTER ROLL NUMBER: ")))
if roll in range(1, len(class_list) + 1):
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{}'.format("",class_list[roll - 1]))
correct_input = 0
while correct_input != 1:
state = input("{: ^9}|{}".format("", "STATE[p/a]: ")).strip()
if state in ['a', 'A', 'p', 'P']:
correct_input = 1
else:
print("{: ^9}|{}".format("", "ERROR: Invalid input!"))
print('\n' + class_list[roll - 1])
if state in ['p', 'P']:
if roll not in students_present:
students_present.append(roll)
students_absent.remove(roll)
elif state in ['a', 'A']:
if roll not in students_absent:
students_absent.append(roll)
students_present.remove(roll)
else:
print("{: ^9}|{}".format("", "ERROR: Roll number does not exist!"))
correct_input = 0
while correct_input != 1:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
verify = int(input("{: ^9}|{}".format("", "EDIT FURTHER?[0:SAVE/ 1:EDIT]: ")))
if verify in [0, 1]:
correct_input = 1
if verify == 0:
print('\n{: ^9}{:-^58}{: ^9}'.format("", "", ""))
save_data()
else:
print("{: ^9}|{}".format("", "ERROR: Invalid input!"))
def mark_attendance():
global students_present
global students_absent
prepare_class_list()
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "ATTENDANCE", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
for roll in range(1, len(class_list) + 1):
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{}.{}'.format("", roll, class_list[roll - 1]))
correct_input = 0
while correct_input != 1:
state = input("{: ^9}|{}".format("", "STATE[p/a]: ")).strip()
if state in ['a', 'A', 'p', 'P']:
correct_input = 1
else:
print("{: ^9}|{}".format("", "INCORRECT STATE! TRY AGAIN."))
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{}'.format("",class_list[roll - 1]))
if state in ['p', 'P']:
students_present.append(roll)
elif state in ['a', 'A']:
students_absent.append(roll)
print('\n{: ^9}{:-^58}{: ^9}'.format("", "", ""))
correct_input = 0
while correct_input != 1:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
verify = input("{: ^9}|{}".format("", "SAVE DATA?[y: SAVE/ n: EDIT]: ")).strip()
if verify in ['y', 'Y', 'n', 'N']:
correct_input = 1
else:
print("{: ^9}|{}".format("", "ERROR: Invalid input!"))
if verify in ['y', 'Y']:
save_data()
elif verify in ['n', 'N']:
edit_data()
if test_string == "[AVAILABLE]\n":
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "ACTIONS", ""))
print('{: ^9}|{:-^56}|{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","1. MARK ATTENDANCE", ""))
print('{: ^9}|{:-^56}|{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","2. MY CLASS", ""))
print('{: ^9}|{:-^56}|{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","3. ABOUT", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","0. QUIT", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
prepare_class_list()
while True:
correct_action = None
while correct_action not in [1, 2, 3, 0]:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
action = int(input('{: ^9}|{}'.format("","CHOOSE ACTION: ")))
if action in [1, 2, 3, 0]:
correct_action = action
else:
print("{: ^9}|{}".format("", "ERROR: Invalid input!"))
if action == 1:
if class_list == []:
print("{: ^9}|{}".format("", "ERROR: No class found!"))
else:
mark_attendance()
elif action == 2:
edit_class()
elif action == 3:
display_about()
elif action == 0:
key = input("{: ^9}|{}".format("", "Press enter to quit....")).strip()
exit()
else:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("", "WELCOME TEACHER!", ""))
print('{: ^9}+{:-^56}+'.format("", ""))
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: ^56}|{: ^9}'.format("","ACTIONS", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","1. CREATE CLASS", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","2. ABOUT", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
print('{: ^9}|{: <56}|{: ^9}'.format("","0. QUIT", ""))
print('{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
while True:
correct_action = None
while correct_action not in [1, 2, 0]:
print('\n{: ^9}+{:-^56}+{: ^9}'.format("", "", ""))
action = int(input('{: ^9}|{}'.format("","CHOOSE ACTION: ")))
if action in [1, 2, 0]:
correct_action = action
else:
print("{: ^9}|{}".format("", "ERROR: Invalid input!"))
if action == 1:
create_class()
elif action == 2:
display_about()
elif action == 0:
key = input("{: ^9}|{}".format("", "Press enter to quit....")).strip()
exit()