Finding Students with Second Lowest Grade – Detailed Version
Автор: CodeVisium
Загружено: 2025-03-24
Просмотров: 39
In this video, we solve the HackerRank problem of finding the student(s) with the second lowest grade in a class using Python. We store student names and grades in a nested list, identify the second lowest grade, and then print the names of all students having that grade in alphabetical order.
Step-by-Step Explanation:
Input Reading:
Read the number of students.
For each student, read the name and grade and store them as a nested list.
#InputHandling #NestedLists
Identify Unique Grades:
Create a sorted list of unique grades to easily determine the second lowest grade.
#Sorting #UniqueValues
Filter Students:
Extract the names of students whose grade matches the second lowest grade.
Sort these names alphabetically.
#Filtering #Sorting
Output:
Print each name on a new line.
#Output #Result
Copy and paste the code below into your Jupyter Notebook to practice the detailed solution!
Code for Detailed Version (Copy-Paste in Jupyter Notebook):
def find_second_lowest_students():
Read the number of students
n = int(input().strip())
students = []
Collect student names and grades
for _ in range(n):
name = input().strip()
grade = float(input().strip())
students.append([name, grade])
Extract a sorted list of unique grades
unique_grades = sorted({grade for name, grade in students})
The second lowest grade
second_lowest = unique_grades[1]
Get names of all students with the second lowest grade and sort them alphabetically
second_lowest_students = sorted([name for name, grade in students if grade == second_lowest])
Print the names of the students
for student in second_lowest_students:
print(student)
if _name_ == '__main__':
find_second_lowest_students()

Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: