A New Name on the Board

Python for AIMedium+10 XP+10

A New Name on the Board

A player asks to change the name shown on the scoreboard. Their points must stay the same.

Write rename_player(scores, old_name, new_name) that moves the points from old_name to new_name, removes old_name, and returns the dictionary.

  • old_name is always on the board.
  • new_name is never already on the board, unless it is the same as old_name. In that case nothing should change, and the player must still be there with their points.

Examples

scores = {'ada': 3, 'grace': 5}
old_name = 'ada'
new_name = 'ada_l'
returns {'grace': 5, 'ada_l': 3}
scores = {"ada": 3, "grace": 5, "linus": 2}
old_name = "linus"
new_name = "torvalds"
returns {'ada': 3, 'grace': 5, 'torvalds': 2}
scores = {"bo": 7}
old_name = "bo"
new_name = "bob"
returns {'bob': 7}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run