Skip to main content

Exercises 26.7 Chapter Exercises

1.

The code below is supposed to change the white in the French flag to aqua (Aqua is made by mixing blue and green with no red). Arrange and indent the blocks to make a correct program. You will not use them all.

2.

Complete the program below so it changes all the green pixels in the image to red.
Hint: The green pixels are not pure green. They have almost as much red as they do green. A sample color value might be 111 red, 115 green, and 65 blue. However, the tan pixels also have a lot of green. A tan pixel might have the colors: 177 red, 129 green, 53 blue. Notice that the tan one has a lot more red than the green pixels. Make sure your recipe selects things that have a lot of green, but also do not have too much red.

3.

We want to make the pixels in the right half of an image turn black. Pixels in the left half of the image should stay the same.
You need to write code to decide if each pixel is on the right half and then, if so, make it black. The image is 300 pixels wide.

4.

Write the function isYellow that accepts red, green, and blue values as its parameters and returns True if both the green and red values are at least 40 more than the blue value. Otherwise, it should return False.
Once you write the function, it will be used to turn the goalkeeper’s jersey from yellow to aqua by swapping the red and blue values.
Hint: Start by writing a function that returns True always. That will let you run the program but will change every pixel. Then add a condition to say True or False based on the r, g, b values passed in.
You have attempted of activities on this page.