We need to take data of students from the user (number of students are given by user) and then store this data in a dictionary. After this, we need to take the roll number of the student whose record is to be searched and find the student’s record and print it. After this we need to print records of all students with percentages greater than 60.
Dictionary in python is a collection that stores all the data in key-value pairs. This data needs to be unique and can be easily accessed.
Example:
student = {
"RollNo" = 1232
"Name" = RamLal
"mathsMark" = 65
"physicsMark" = 55
"chemistryMark" = 87
}
Dictionary in Python is useful as it supports many in-built functions to perform different operations on the data stored in it. Here, we need searching and filtering.
Searching for a specific record using the get() method, using a dictionary we can use the python's inbuilt method get() which will search for a student record with a given roll number in the dictionary.
Printing student records with percentages greater than 60, we will do this by applying a filter method on student’s records.
Program to search student record stored using Dictionary
Output
Explanation:
In the above code, we have created a dictionary studentDict to store students data. And then asked the user to enter the records and store it into studentDict (repeated records were deleted). Then we asked the user to enter the roll number of the student whose record is to be searched which then is extracted from the dictionary using the get() method. After this we have applied a filter to print the list of all students who got marks more than 60%.
need an explanation for this answer? contact us directly to get an explanation for this answer