Unit 2 Session 2 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: If the player is already in the dict, add points to their score, otherwise, make a new entry in the dict for them.
1) Check if player is in the dict
2) If so, add points to that player's current score
3) Otherwise, map player -> points in the dict
4) Return the updated dict
⚠️ Common Mistakes
KeyError
.def update_score(scores, player, points):
if player in scores:
scores[player] += points
else:
scores[player] = points
return scores