Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
For this dictionary, write the expression for each answer.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Read each expression from left to right, one key at a time.
school["7B"]["teacher"] gives "Mr Khan".school["7A"]["marks"][1] gives 75. The first positions start at 0, so the second mark is position 1.sum(school["7B"]["marks"]) / len(school["7B"]["marks"]) gives 67.5, which is 135 divided by 2.school["7C"] = {"teacher": "Ms Das", "marks": [70, 85]} adds the new record.Check. Run the lines in a program, and print school at the end to see the new class.
Answer: "Mr Khan", 75, 67.5, and the new record as in line 4.
Log in to join the discussion.
Loading…