Code....
Building a Student Ranking System in Python..
Have you ever wondered how teachers can quickly arrange students’ marks into a ranking list? Instead of doing it manually, we can use Python programming to make this task super easy.
Take student names and marks as input.
Sort students in descending order (highest marks first).
Display the rankings.`
Save the results into a text file.
Step 1: Collect Student Data..
We start by asking the user how many students are in the class. Then, we take the name and marks of each student.
Here, we store each student’s name and marks as a tuple inside a list. Example:
[("Alice", 90), ("Bob", 85)].Step 2: Sort Students by Marks
Now that we have the data, we need to sort it based on marks in descending order (highest to lowest).
* Reverse=True ensures highest marks come first.* The
sorted() function arranges the students based on marks.Step 3: Display the Rankings..
After sorting, we print the rankings on the screen.
Step 4: Save Rankings to a File
Finally, we save the results into a file called class_rankings.txt.
Comments
Post a Comment