Replace marks with their average
Write a Python program to replace the numeric marks p1 and p2 with a single average entry.
{"name": "ketan", "subject": "maths", "p1": 80, "p2": 70}{'name': 'ketan', 'subject': 'maths', 'average': 75.0}Approach
- Pop both marks and store their average under a new key.
Solution
d = {"name": "ketan", "subject": "maths", "p1": 80, "p2": 70}p1, p2 = d.pop("p1"), d.pop("p2")d["average"] = (p1 + p2) / 2print(d){'name': 'ketan', 'subject': 'maths', 'average': 75.0}Learn the concept
New to this topic? Read the lesson, then come back.