Create a dictionary to store 4 student details with roll no. , name, age field. Search students on the list.
Answers
Answer:
Dictionary
Explanation:
The Python list stores a collection of objects in an ordered sequence. In contrast, the dictionary stores objects in an unordered collection. However, dictionaries allow a program to access any member of the collection using a key – which can be a human-readable string.
Answer:
students = {'Aman':{'Roll Number':'1', 'Age':'18','Field': 'PCM'},
'Raj':{'Roll Number':'2', 'Age':'18','Field': 'PCB'},
'Suresh':{'Roll Number':'3', 'Age':'18','Field': 'Commerce'},
'Mukesh':{'Roll Number':'4', 'Age':'18','Field': 'Arts'}}
n = input("Enter name of student : ")
student1 = students[n]
print(student1)
In the above program we have created a dictionary for 4 students and then on running the program it will ask the "Name of Student" for searching from the dictionary and print it's details.
Dictionary in Python is used to store data values in an unordered collection. For storing data in dictionary keys are used. It's like key:value pair in which data is hold by unique keys.