Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function increment(grid) that takes an existing 2-D list of digits and i

ID: 3740188 • Letter: W

Question

Write a function increment(grid) that takes an existing 2-D list of digits and increments each digit by 1. If incrementing a given digit causes it to become a 10 (i.e., if the original digit was a 9), then the new digit should “wrap around” and become a 0.

Important notes:

Unlike the other functions that you wrote for this problem, this function should notcreate and return a new 2-D list. Rather, it should modify the internals of the existing list.

Unlike the other functions that you wrote for this problem, this function should nothave a return statement, because it doesn’t need one! That’s because its parametergrid gets a copy of the reference to the original 2-D list, and thus any changes that it makes to the internals of that list will still be visible after the function returns.

The loops in this function need to loop over all of the cells in the grid, not just the inner cells.

For example:

Here’s another example that should help to reinforce your understanding of references:

Explanation / Answer

def increment(grid): for lst in grid: for i in range(len(lst)): lst[i] += 1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote