-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab11.py
More file actions
79 lines (74 loc) · 3.38 KB
/
Copy pathLab11.py
File metadata and controls
79 lines (74 loc) · 3.38 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
#Grade Calculator
import matplotlib.pyplot as plt
import os
directory = "data/submissions"
assignmentIDs = []
grades = []
found = False
print("1. Student grade\n2. Assignment statistics\n3. Assignment graph")
option = int(input("Enter your selection: "))
if option == 1:
studentName = input("What is the student's name: ")
with (open("data/students.txt", "r") as studentsList):
for student in studentsList.readlines():
if student.strip()[3:] == studentName:
studentID = student[:3]
found = True
for file in os.listdir(directory):
with open("data/submissions/" + file, "r") as txt:
content = txt.read()
if content[:3] == studentID:
temp = content[4:].strip()
index = temp.index("|")
if index != -1:
assignmentIDs.append(temp[:index])
grades.append(int(temp[index + 1:]))
for i in range(len(assignmentIDs)):
with open("data/assignments.txt", "r") as txt:
lines = txt.readlines()
for j in range(len(lines) + 1):
if lines[j].strip() == assignmentIDs[i]:
weight = int(lines[j + 1].strip()) / 100
grades[i] *= weight
break
totalGrade = sum(grades) / 10
print(f"{totalGrade:.0f}%")
if not(found):
print("Student not found")
elif option == 2:
assignmentName = input("What is the assignment name: ")
with open("data/assignments.txt", "r") as txt:
lines = txt.readlines()
for i in range(len(lines)):
if lines[i].strip() == assignmentName:
assignmentID = int(lines[i + 1].strip())
found = True
for file in os.listdir(directory):
with open("data/submissions/" + file, "r") as txt:
content = txt.read()
stuff = content.split("|")
if int(stuff[1]) == assignmentID:
grades.append(int(stuff[2]))
print(f"Min: {min(grades)}%")
print(f"Avg: {int(sum(grades) / len(grades))}%")
print(f"Max: {max(grades)}%")
if not(found):
print("Assignment not found")
elif option == 3:
assignmentName = input("What is the assignment name: ")
with open("data/assignments.txt", "r") as txt:
lines = txt.readlines()
for i in range(len(lines)):
if lines[i].strip() == assignmentName:
assignmentID = int(lines[i + 1].strip())
found = True
for file in os.listdir(directory):
with open("data/submissions/" + file, "r") as txt:
content = txt.read()
stuff = content.split("|")
if int(stuff[1]) == assignmentID:
grades.append(int(stuff[2]))
plt.hist(grades, bins = range(50, 101, 5), color = "g", edgecolor = "w")
plt.show()
if not(found):
print("Assignment not found")