-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit3challenge 2
27 lines (23 loc) · 890 Bytes
/
Unit3challenge 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Student:
def __init__(self, name, roll_number, cgpa):
self.name = name
self.roll_number = roll_number
self.cgpa = cgpa
def sort_students(student_list):
# Sort the student list based on the cgpa attribute in descending order
sorted_students = sorted(student_list, key=lambda student: student.cgpa, reverse=True)
return sorted_students
# Example usage
if __name__ == "__main__":
# Create a list of student objects
students = [
Student("Alice", "A001", 3.9),
Student("Bob", "B002", 3.7),
Student("Charlie", "C003", 4.0),
Student("David", "D004", 3.5),
]
# Sort the students based on CGPA
sorted_students = sort_students(students)
# Print the sorted list
for student in sorted_students:
print(f"Name: {student.name}, Roll Number: {student.roll_number}, CGPA: {student.cgpa}")