From fb8217569f48862edaab79c19e83dad71f00face Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Tue, 5 Aug 2025 11:27:10 +0000 Subject: [PATCH] [Sync Iteration] python/making-the-grade/1 --- solutions/python/making-the-grade/1/loops.py | 98 ++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 solutions/python/making-the-grade/1/loops.py diff --git a/solutions/python/making-the-grade/1/loops.py b/solutions/python/making-the-grade/1/loops.py new file mode 100644 index 0000000..ecaffbe --- /dev/null +++ b/solutions/python/making-the-grade/1/loops.py @@ -0,0 +1,98 @@ +"""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. + """ + new_scores = [] + for index, score in enumerate(student_scores): + new_scores.append(round(score)) + return new_scores + pass + + +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. + """ + count = 0 + for score in student_scores: + if score <= 40: + count += 1 + return count + pass +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_list = [] + for score in student_scores: + if score >= threshold: + best_list.append(score) + return best_list + pass + + +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 + """ + new_list = [] + start = 41 + for i in range(4): + new_list.append(start) + start += (highest - 40) // 4 + return new_list + pass + + +def student_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 [". : "]. + """ + new_list = [] + for i in range(len(student_names)): + new_list.append(str(i + 1) + ". " + student_names[i] + ": " + str(student_scores[i])) + return new_list + pass + + +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 [, ] lists. + :return: list - first `[, 100]` or `[]` if no student score of 100 is found. + """ + new_list = [] + isFound = False + perfect_index = 0 + for i in range(len(student_info)): + if student_info[i][1] == 100: + perfect_index = i + isFound = True + break + if isFound: + return student_info[perfect_index] + else: + return [] +#print(perfect_score([['Joci', 100], ['Vlad', 100], ['Raiana', 100], ['Alessandro', 100]])) \ No newline at end of file