Repository navigation
Expand file tree
/
Copy pathCourse_grading(write).py
More file actions
78 lines (64 loc) · 2.3 KB
/
Copy pathCourse_grading(write).py
File metadata and controls
78 lines (64 loc) · 2.3 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
if True:
student_info = input("Student information: ")
exercise_data = input("Exercises completed: ")
exam_info=input("Exam points: ")
course_info=input("Course information: ")
else:
student_info = "students1.csv"
exercise_data = "exercises1.csv"
exam_info="exam_points1.csv"
course_info="course1.txt"
def to_points(points):
return points//4
def grade(points):
a = 0
limits = [15, 18, 21, 24, 28]
while a < 5 and points >= limits[a]:
a += 1
return a
name={}
with open(student_info) as new_file:
for lines in new_file:
lines = lines.replace("\n", "")
list_of_name=lines.split(";")
if list_of_name[0]=="id":
continue
name[list_of_name[0]]=list_of_name[1]+" "+list_of_name[2]
exercise={}
with open(exercise_data) as new_files:
for lines in new_files:
sum=0
lines = lines.replace("\n", "")
list_of_ex=lines.split(";")
if list_of_ex[0]=="id":
continue
for i in range(1,len(list_of_ex)):
sum+=int(list_of_ex[i])
exercise[list_of_ex[0]]=sum
exam={}
with open(exam_info) as exam_file:
for lines in exam_file:
sum=0
lines = lines.replace("\n","")
list_of_exam= lines.split(";")
if list_of_exam[0]=="id":
continue
for i in range(1,len(list_of_exam)):
sum+=int(list_of_exam[i])
exam[list_of_exam[0]]=sum
with open("results.txt","w") as new_file, open(course_info) as reading_file, open("results.csv","w") as writing_file :
heading=""
char="="
for lines in reading_file:
lines=lines.split(":")
if lines[0]=="study credits":
heading+=f"{lines[1].strip()} credits \n"
continue
heading+=(f"{lines[1].strip()}, ")
new_file.write(heading)
heading=heading.strip()
new_file.write(f"{char*len(heading)}\n")
new_file.write("name"+" "*26+"exec_nbr"+" "+"exec_pts."+" "+"exm_pts."+" "+"tot_pts."+" "+"grade\n")
for id,names in name.items():
new_file.write(f"{names:30}{exercise[id]:<10}{to_points(exercise[id]):<10}{exam[id]:<10}{to_points(exercise[id])+exam[id]:<10}{grade(to_points(exercise[id])+exam[id]):<10}\n")
writing_file.write(f"{id};{names};{grade(to_points(exercise[id])+exam[id])} \n")