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 geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course