Advertisement
kingbode

Untitled

Dec 24th, 2023
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. def get_student_name(students):
  2.     """
  3.    This function takes a dictionary of students and their grades
  4.    and returns the name(s) of the student(s) with the lowest grade above the minimum grade
  5.    """
  6.     min_grade = min(students.values())
  7.     # sort the dictionary by values
  8.     students = sorted(students.items(), key=lambda x: x[1])
  9.  
  10.     results = []
  11.     result = None
  12.  
  13.     for name, grade in students:
  14.         if grade > min_grade and not results:
  15.             results.append(name)
  16.             result = grade
  17.         elif grade == result:
  18.             results.append(name)
  19.         else:
  20.             continue
  21.  
  22.     return results
  23.  
  24.  
  25. students = {'r': 0, 'b': 0, 'c': 3, 'n': 10, 'e': 50 , 'a': 3}
  26. print(get_student_name(students))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement