Solution: Class Grades
We'll cover the following...
This program stores a list of students with their scores and then prints each student’s name and score.
studentsis a list containing dictionaries.Each dictionary represents one student with two pieces of information:
"name"→ the student’s name"score"→ their test score
The
forloop goes through each student dictionary one by one.Inside the loop:
student['name']gets the student’s name.student['score']gets their score.
The
print()statement displays both pieces of data in one sentence.
Python
students = [{"name": "Sam", "score": 87},{"name": "Luna", "score": 92},{"name": "Kai", "score": 78}]for student in students:print(student['name'], "scored", student['score'])