Everything about one student, in one box
A list holds many marks, but it does not know what any of them mean. marks[2] is the third mark — of what subject, for which student? You have to remember, and remembering is exactly what goes wrong at two in the morning.
A dictionary holds values the same way a list does, but each one is filed under a name you chose rather than a position you have to count to.
student = {'name': 'Anjali More', 'roll': 17}The key is the label you file it under. The value is the thing itself. Keys are usually short pieces of text and must be exact —
'marks' and 'Marks' are two different labels, as far apart as two different words.student['name'].student[0] does not mean the first item. A dictionary has no first item to speak of — it only has labels — so Python goes looking for a key called 0, fails to find one, and stops.student['grade'] stops the programme if there is no grade recorded. Often that is what you want: a missing field is a real problem and you would rather know.But sometimes it is normal for a field to be absent.
student.get('grade', 'not recorded') hands back the grade if it exists and your fallback if it does not, and the programme carries on. Choosing between these two is a judgement about your data, not about Python.That is how you add a field on purpose. It is also how a typo silently gives you a record with both
'marks' and 'Marks' in it, one of them right and one of them ignored by everything else you write.What you are building
Build the programme
Your plan
The steps still to place
The whole programme is laid out below. Five pieces are missing. Watch the two that involve a key you may have typed slightly wrong — a dictionary will not warn you about either of them.
Leave nothing on "choose…". A wrong pick does not always cause an error — sometimes it just prints something you did not expect, which is the harder kind of mistake to spot.
Run and read
Here is the whole programme. The name, the marks and the field to look up are all yours to change. Try looking up a field that exists and one that does not.