-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrial.py
349 lines (299 loc) · 11.1 KB
/
trial.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
import json # json is a function to allow dictionaries to be written in files
def teacher():#This function takes the course id from the teacher then takes this course students' grades
group1 = [111]
group2 = [112]
english = [156]
ethics = [150]
finish = 'y'
while finish == 'y':
while True:
try:
id = int(input('Enter course ID:'))
while id not in ethics and id not in english:
id = int(input('Error! enter correct course id:'))
break
except:
print('Eror!only numbers are allowed ')
if id in english:
while True:
try:
group = int(input('Group number:'))
while group not in group1 and group not in group2:
while True:
try:
group = int(input('Error! Enter correct group:'))
break
except:
print('Error only numbers are allowed')
if group in group1:
id_grade_156_1()
elif group in group2:
id_grade_156_2()
break
except:
print('Error only numbers are allowed')
elif id in ethics:
while True:
try:
group = int(input('Group number:'))
while group not in group1 and group not in group2:
group = int(input('Error! Enter correct group:'))
if group in group1:
id_grade_150_1()
elif group in group2:
id_grade_150_2()
break
except:
print('Error only numbers are allowed')
while True:
try:
finish = input("Do you want to add other grades for other groups or subjects ? '(y) for yes or any button for (no):")
break
except:
print('Error only enter letters')
return
def id_grade_156_1():#This function takes the group 1 English grades from the teacher and inputs it into a file
group1_id = [202201, 202202, 202203, 202204, 202205]
i = 5
id_student1 = {}
abs_student1={}
while i > 0:
while True :
try:
stu_id1 = (int(input('Enter student Id:')))
break
except:
print('Error only numbers are allowed')
while stu_id1 not in group1_id:
while True:
try:
stu_id1 = int(input('Error! please enter correct ID:'))
break
except:
print('Error only enter numbers')
while True:
try:
stu_grade1 = (int(input('Enter grade of student:')))
break
except:
print('Error enter numbers only')
while stu_grade1 > 100 or stu_grade1 < 0:
while True:
try:
stu_grade1 = (int(input('Error!please enter correct grades:')))
break
except:
print('Error enter numbers only')
id_student1[stu_id1] = stu_grade1
i -= 1
abs_student1[stu_id1] = absence()
if i >= 1:
while True:
try:
cont = input("if you are done adding grades enter (y)if not press any button :")
break
except:
print('Error enter letters only')
if cont == 'y':
break
file = open('file156(g).txt', 'w')
# ('Group (1) English grades: ')
file.write(json.dumps(id_student1))
# json.dumps is a function to allow dictionaries to be written in files
file.write('\n')
file.close()
# file.write('group (1) absence days in English:')
file1=open('file156(a).txt','w')
file1.write(json.dumps(abs_student1))
file1.write('\n')
file1.close()
return file,file1
def id_grade_156_2():#This function takes the group 2 English grades from the teacher and inputs it into a file
group2_id=[202206,202207,202208,202209,202210]
i=5
id_student2 = {}
abs_student2 = {}
while i > 0:
while True:
try:
stu_id2 = (int(input('Enter student Id:')))
break
except:
print('Error enter numbers only')
while stu_id2 not in group2_id:
while True:
try:
stu_id2 = int(input('Error! please enter correct ID:'))
break
except:
print('Error enter numbers only')
while True:
try:
stu_grade2 = (int(input('Enter grade of student:')))
break
except:
print('Error enter numbers only')
while stu_grade2 > 100 or stu_grade2 < 0:
while True:
try:
stu_grade2 = (int(input('Error!please enter correct grades:')))
break
except:
print('Error enter numbers only')
id_student2[stu_id2] = stu_grade2
abs_student2[stu_id2] = absence()
i -= 1
if i >= 1:
while True:
try:
cont = input("if you are done adding grades enter (y)if not press any button ")
break
except:
print('Error enter letters only')
if cont == 'y':
break
file2 = open('file156(g2).txt', 'w')
# ('Group (2) English grades: ')
file2.write(json.dumps(id_student2))
# json.dumps is a function to allow dictionaries to be written in files
file2.write('\n')
file2.close()
# ('group (2) absence days in English:')
file3=open('file156(a2).txt',"w")
file3.write(json.dumps(abs_student2))
file3.write('\n')
file3.close()
return file2,file3
def id_grade_150_1():#This function takes the group 1 Ethics grades from the teacher and inputs it into a file
group1_id = [202201, 202202, 202203, 202204, 202205]
i = 5
id_student1 = {}
abs_student1 = {}
while i > 0:
while True:
try:
stu_id1 = (int(input('Enter student Id:')))
break
except:
print('Error enter numbers only')
while stu_id1 not in group1_id:
while True:
try:
stu_id1 = int(input('Error! please enter correct ID:'))
break
except:
print('Error enter numbers only')
while True:
try:
stu_grade1 = (int(input('Enter grade of student:')))
break
except:
print('Error enter numbers only')
while stu_grade1 > 100 or stu_grade1 < 0:
while True:
try:
stu_grade1 = (int(input('Error!please enter correct grades:')))
break
except:
print('Error enter numbers only')
id_student1[stu_id1] = stu_grade1
abs_student1[stu_id1] = absence()
i -= 1
if i >= 1:
while True:
try:
cont = input("if you are done adding grades enter (y)if not press any button :")
break
except:
print('Error enter letter only')
if cont == 'y':
break
file4 = open('file150(g).txt', 'w')
# if written in here file will reset grades
#('Group (1) Ethics grades: ')
file4.write(json.dumps(id_student1))
# json.dumps is a function to allow dictionaries to be written in files
file4.write('\n')
file4.close()
#file.write('group (1) absence days in Ethics:')
file5=open('file150(a).txt','w')
file5.write(json.dumps(abs_student1))
file5.write('\n')
file5.close()
return file5,file4
def id_grade_150_2():#This function takes the group 2 Ethics grades from the teacher and inputs it into a file
group2_id = [202206, 202207, 202208, 202209, 202210]
i = 5
id_student2 = {}
abs_student2 = {}
while i > 0:
while True:
try:
stu_id2 = (int(input('Enter student Id:')))
break
except:
print('Error enter numbers only')
while stu_id2 not in group2_id:
while True:
try:
stu_id2 = int(input('Error! please enter correct ID:'))
break
except:
print('Error enter numbers only')
while True:
try:
stu_grade2 = (int(input('Enter grade of student:')))
break
except:
print('Error enter numbers only')
while stu_grade2 > 100 or stu_grade2 < 0:
while True:
try:
stu_grade2 = (int(input('Error!please enter correct grades:')))
break
except:
print('Error enter numbers only')
id_student2[stu_id2] = stu_grade2
i -= 1
abs_student2[stu_id2] = absence()
if i >= 1:
while True:
try:
cont = input("if you are done adding grades enter (y)if not press any button :")
break
except:
print('Error enter numbers only')
if cont == 'y':
break
file6 = open('file150(g2).txt', 'w')
#('Group (2) Ethics grades: ')
file6.write(json.dumps(id_student2))
# json.dumps is a function to allow dictionaries to be written in files
file6.write('\n')
file6.close()
#('group (2) absence days in Ethics:')
file7 = open('file150(a2).txt','w')
file7.write(json.dumps(abs_student2))
file7.write('\n')
file7.close()
return file7,file6
def absence():#This function takes the grabsence days from the teacher and inputs it into a file
abs=(int(input('Enter absence days:')))
while abs < 0 or abs > 15:
while True:
try:
abs = int(input('Error! PLease enter correct absence days:'))
break
except:
print('Error enter numbers only')
return abs
if __name__ == "__main__":
teacher()
file = open("file156.txt", 'r')
for line in file:
print(line)
file.close()
file2 = open('file150.txt', 'r')
for line2 in file2:
print(line2)
file2.close()