-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse grading project using csv
More file actions
82 lines (77 loc) · 2.87 KB
/
Copy pathCourse grading project using csv
File metadata and controls
82 lines (77 loc) · 2.87 KB
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
student=input('Student information: ')
exercise=input('Exercises completed: ')
exam=input('Exam points: ')
course=input('Course: ')
with open(course) as header:
course1=[]
for line in header:
line= line.replace('\n','')
linelist=line.split(':')
course1.append(linelist[1].strip())
names= {}
with open(student) as students:
for line in students:
line=line.replace('\n', '')
parts = line.split(';')
if parts[0]=='id':
continue
names[parts[0]]=parts[1] + ' ' + parts[2]
points={}
exec1={}
with open(exercise) as exercises:
for line in exercises:
parts= line.split(';')
if parts[0]=='id':
continue
points[parts[0]]= int(((int(parts[1])+int(parts[2])+int(parts[3])+int(parts[4])+int(parts[5])+int(parts[6])+int(parts[7]))/40)*10)
exec1[parts[0]]=int(parts[1])+int(parts[2])+int(parts[3])+int(parts[4])+int(parts[5])+int(parts[6])+int(parts[7])
exam1={}
with open(exam) as exams:
for line in exams:
parts= line.split(';')
if parts[0]=='id':
continue
exam1[parts[0]]=int(parts[1])+int(parts[2])+int(parts[3])
grade={}
totals={}
for id in points:
if id in exam1:
totals[id]=points[id]+exam1[id]
grade[id]=points[id]+exam1[id]
if grade[id]<15:
grade[id]=0
elif grade[id]<18 and grade[id]>=15:
grade[id]=1
elif grade[id]<21 and grade[id]>=18:
grade[id]=2
elif grade[id]<24 and grade[id]>=21:
grade[id]=3
elif grade[id]<28 and grade[id]>=24:
grade[id]=4
elif grade[id]>=28:
grade[id]=5
with open('results.txt','w') as result:
result.write(f'{course1[0]}, {course1[1]} credits\n')
result.write(len(f'{course1[0]}, {course[1]} credits')*'=')
result.write('\n')
result.write('name exec_nbr exec_pts. exm_pts. tot_pts. grade\n')
for id, name in names.items():
if id in grade:
grad=grade[id]
point=points[id]
num=exec1[id]
exam0=exam1[id]
total=totals[id]
if exam0>9 and point!=0:
result.write(f'{name:16}{14*' '}{num}{8*' '}{point}{9*' '}{exam0}{8*' '}{total}{8*' '}{grad}\n')
elif point==10:
result.write(f'{name:16}{14*' '}{num}{8*' '}{point}{8*' '}{exam0}{9*' '}{total}{8*' '}{grad}\n')
elif num<10:
result.write(f'{name:16}{14*' '}{num}{9*' '}{point}{9*' '}{exam0}{8*' '}{total}{8*' '}{grad}\n')
else:
result.write(f'{name:16}{14*' '}{num}{8*' '}{point}{9*' '}{exam0}{9*' '}{total}{8*' '}{grad}\n')
with open('results.csv','w') as listers:
for id in grade:
listers.write(f'{id};{names[id]};{grade[id]}')
listers.write('\n')
print('Results written to files results.txt and results.csv')