Fix the Shared List Bug
Python
25 pts
Fix the Shared List Bug
This function should put a student into a group. If no group is given, it should start a new, empty group. But it has the mutable default bug: run it and you will see Abel appear in Selam’s group.
Fix add_student(name, group=...) so that:
add_student("Selam")returns['Selam']add_student("Abel")returns['Abel'](a fresh list)add_student("Abel", ["Merhawi"])returns['Merhawi', 'Abel']
Expected output:
['Selam'] ['Abel'] ['Merhawi', 'Abel']
Checklist
- Keep
add_student, but change the default so that every call without a group starts a new, empty list. - When a group is given, add the name to that same list and return it.
- Print the three calls given at the bottom.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
