Project: Square a list in place

Write a function called square_list that takes a list of numbers and replaces each value with its square. It does not return anything. It changes the original list.

nums = [7, -3, 12, 9]
square_list(nums)
print(nums)  # This should print [49, 9, 144, 81]

Save the file as square_list.py.

Show a solution

Try the project on your own first. This is one working solution, followed by its tests. Press Run to run the tests. Read them to see what thorough testing looks like, then change the solution and run again to watch a test fail.

Projects run on your own computer, so you tell us when you are done.