-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.py
More file actions
97 lines (72 loc) · 2.87 KB
/
loops.py
File metadata and controls
97 lines (72 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""Functions for organizing and calculating student exam scores."""
def round_scores(student_scores):
"""Round all provided student scores.
:param student_scores: list - float or int of student exam scores.
:return: list - student scores *rounded* to nearest integer value.
"""
rounds = []
for score in student_scores:
rounds.append(round(score))
return rounds
def count_failed_students(student_scores):
"""Count the number of failing students out of the group provided.
:param student_scores: list - containing int student scores.
:return: int - count of student scores at or below 40.
"""
fails = 0
for score in student_scores:
if score <= 40:
fails += 1
return fails
def above_threshold(student_scores, threshold):
"""Determine how many of the provided student scores were 'the best'
based on the provided threshold.
:param student_scores: list - of integer scores.
:param threshold: int - threshold to cross to be the "best" score.
:return: list - of integer scores that are at or above the "best"
threshold.
"""
best_scores = []
for score in student_scores:
if score >= threshold:
best_scores.append(score)
return best_scores
def letter_grades(highest):
"""Create a list of grade thresholds based on the provided highest grade.
:param highest: int - value of highest exam score.
:return: list - of lower threshold scores for each D-A letter
grade interval.
For example, where the highest score is 100, and failing is <= 40,
The result would be [41, 56, 71, 86]:
41 <= "D" <= 55
56 <= "C" <= 70
71 <= "B" <= 85
86 <= "A" <= 100
"""
letters = []
step = round((highest - 40) / 4)
for index in range(4):
letters.append(41 + step * index)
return letters
def student_ranking(student_scores, student_names):
"""Organize the student's rank, name, and grade information in ascending order.
:param student_scores: list - of scores in descending order.
:param student_names: list - of string names by exam score in
descending order.
:return: list - of strings in format ["<rank>. <student name>: <score>"].
"""
ranking = []
for index, _ in enumerate(student_scores):
ranking.append(f"{index + 1}. {student_names[index]}: {student_scores[index]}")
return ranking
def perfect_score(student_info):
"""Create a list that contains the name and grade of the first student
to make a perfect score on the exam.
:param student_info: list - of [<student name>, <score>] lists.
:return: list - first `[<student name>, 100]` or `[]` if no student
score of 100 is found.
"""
for student in student_info:
if student[1] == 100:
return student
return []