TIER 0 / invert-an-image

Your first image: inverting pixels

An image is just numbers

The variable image below is a list of rows. Each row is a list of numbers, one per pixel: 0 is black, 255 is white.

To invert an image you replace every pixel p with 255 - p. Dark becomes light and light becomes dark.

Use two for loops - one over the rows, one over the pixels in each row - and build a new list called inverted.

You will write this by hand now. At Tier 1 you'll do the whole thing in one line with numpy, and it will mean far more having done it the slow way first.

Loading Python (runtime)…