A bonus that keeps the original scores
Code review · Medium · §8.5, §3.5 Inside and outside a function
This code is meant to make a new list of scores with a bonus added and leave the original scores as they are. It runs without an error, but the original scores change too. Fix just one place inside the function so that the output is Before: [70, 85, 90] and After: [75, 90, 95]. Grading also calls the function with a different list.
Code to fix
def add_bonus_all(scores, bonus):
for i in range(len(scores)):
scores[i] = scores[i] + bonus
return scores
before = [70, 85, 90]
after = add_bonus_all(before, 5)
print("Before:", before)
print("After:", after)Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.