From 400938f3a8b9fb88e0c0eaee5a51c89af81b18dc Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2026 14:48:24 +0000 Subject: [PATCH] [Sync Iteration] python/making-the-grade/1 --- solutions/python/making-the-grade/1/loops.py | 107 +++++++++++++++++++ 1 file changed, 107 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 000000000000..9a27821050a5 --- /dev/null +++ b/solutions/python/making-the-grade/1/loops.py @@ -0,0 +1,107 @@ +"""Functions for organizing and calculating student exam scores.""" + + +def round_scores(student_scores): + """Round all provided student scores. + + Parameters: + student_scores (list[float]): Student exam scores. + + Returns: + list[int]: Student scores *rounded* to the nearest integer value. + """ + new = [] + for element in student_scores: + new.append(round(element)) + return(new) + + + +def count_failed_students(student_scores): + """Count the number of failing students out of the group provided. + + Parameters: + student_scores (list[int]): Student scores as ints. + + Returns: + int: The count of student scores at or below 40. + """ + number = 0 + for element in student_scores: + if element<=40: + number+=1 + return(number) + +def above_threshold(student_scores, threshold): + """Determine how many of the provided student scores were 'the best' based on the provided threshold. + + Parameters: + student_scores (list[int]): Integer scores. + threshold (int): The threshold to cross to be the "best" score. + + Returns: + list[int]: Integer scores that are at or above the "best" threshold. + """ + best = [] + for element in student_scores: + if element>= threshold: + best.append(element) + return(best) + + +def letter_grades(highest): + """Create a list of grade thresholds based on the provided highest grade. + + Parameters: + highest (int): The value of the highest exam score. + + Returns: + list[int]: 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 + """ + margin = (highest - 40)//4 + grades = [41] + for i in range(1,4): + grades.append(grades[i-1]+margin) + return(grades) + pass + + +def student_ranking(student_scores, student_names): + """Organize the student's rank, name, and grade information in descending order. + + Parameters: + student_scores (list): Scores in descending order. + student_names (list[str]): Student names by exam score in descending order. + + Returns: + list[str]: Strings in format [". : "]. + """ + ranking = [] + for i,student in enumerate(student_names, start = 1): + rank = str(i) + ". " + student + ": " + str(student_scores[i-1]) + ranking.append(rank) + 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. + + Parameters: + student_info (list[list[str, int]]): List of [, ] lists. + + Returns: + list: First `[, 100]` found OR `[]` if no student score of 100 is found. + """ + First = [] + for element in student_info: + if element[1]==100: + First=element + break + return First