"""Functions for organizing and calculating student exam scores."""defround_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.
"""student_scores_rounded=[]forscoreinstudent_scores:student_scores_rounded.append(round(score))returnstudent_scores_roundeddefcount_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.
"""failed_students:int=0forscoreinstudent_scores:ifscore<=40:failed_students+=1returnfailed_studentsdefabove_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.
"""scores_above_threshold=[]forscoreinstudent_scores:ifscore>=threshold:scores_above_threshold.append(score)returnscores_above_thresholddefletter_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
"""low_score=41no_grades=4# A B C D
threshold_increment=round((highest-low_score)/no_grades)lower_threshold=[]forindexinrange(no_grades):lower_threshold.append(low_score+(threshold_increment*index))returnlower_thresholddefstudent_ranking(student_scores,student_names):"""Organize the student's rank, name, and grade information in descending 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>"].
"""rank_list=[]forindex,(name,score)inenumerate(zip(student_names,student_scores)):rank_list.append(f"{index+1}. {name}: {score}")returnrank_listdefperfect_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.
"""forinfoinstudent_info:ifinfo[1]==100:returninforeturn[]