-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPart 4 - Grade Statistics - 2.py
47 lines (38 loc) · 1.23 KB
/
Part 4 - Grade Statistics - 2.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
def exam_and_exercise_completed(inpt):
space = inpt.find(" ")
exam = int(inpt[:space])
exercise = int(inpt[space+1:])
return [exam, exercise]
def exercise_points(amount):
return amount // 10
def grade(points):
boundary = [0, 15, 18, 21, 24, 28]
for i in range(5, -1, -1):
if points >= boundary[i]:
return i
def mean(points):
return sum(points) / len(points)
def main():
points = []
grades = [0] * 6
while True:
inpt = input("Exam points and exercises completed: ")
if len(inpt) == 0:
break
exam_and_exercises = exam_and_exercise_completed(inpt)
exercise_pnts = exercise_points(exam_and_exercises[1])
total_points = exam_and_exercises[0] + exercise_pnts
points.append(total_points)
grd = grade(total_points)
if exam_and_exercises[0] < 10:
grd = 0
grades[grd] += 1
pass_pros = 100 * (len(points) - grades[0]) / len(points)
print("Statistics:")
print(f"Points average: {mean(points):.1f}")
print(f"Pass percentage: {pass_pros:.1f}")
print("Grade distribution:")
for i in range(5, -1, -1):
stars = "*" * grades[i]
print(f" {i}: {stars}")
main()