Python program for arranging the students according to their marks in descending order
Consider a class of 20 students whose names and marks are given to you. The task is to arrange the students according to their marks in decreasing order. Write a python program to perform the task.
Input: Arun: 78% Geeta: 86% Shilpi: 65% Output: Geeta: 86% Arun: 78% Shilpi: 65%
Approach: Since problem states that we need to collect student name and their marks first so for this we will take inputs one by one in the list data structure then sort them in reverse order using sorted() built-in function based on the student’s percentage and in the last we will print the value accordingly.
Below is the implementation:
-----Program for printing student name with marks using list----- How many student record you want to store?? 3 Enter the student name and percentage: Arun: 78% Enter the student name and percentage: Geeta: 86% Enter the student name and percentage: Shilpi: 65% Sorted list of students according to their marks in descending order Geeta: 86% Arun: 78% Shilpi: 65%
Attention reader! Don’t stop learning now. Join the First-Step-to-DSA Course for Class 9 to 12 students , specifically designed to introduce data structures and algorithms to the class 9 to 12 students