-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGPA.py
More file actions
29 lines (23 loc) · 906 Bytes
/
Copy pathCGPA.py
File metadata and controls
29 lines (23 loc) · 906 Bytes
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
28
29
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):
sorted_students = sorted(student_list, key=lambda student: student.cgpa, reverse=True)
return sorted_students
def create_student():
name = input("Enter student name: ")
roll_number = input("Enter student roll number: ")
cgpa = float(input("Enter student CGPA: "))
return Student(name, roll_number, cgpa)
# Input the list of students
num_students = int(input("Enter the number of students: "))
students = []
for _ in range(num_students):
student = create_student()
students.append(student)
sorted_students = sort_students(students)
print("Sorted Students:")
for student in sorted_students:
print(f"Name: {student.name}, Roll Number: {student.roll_number}, CGPA: {student.cgpa}")