15.7. Exam Questions for Chapters 14 and 15¶
The following questions test what you have learned in chapters 14 and 15. Click the “Start” button when you are ready to begin the exam. Click the “Pause” button to pause the exam (you will not be able to see the questions when the exam is paused). It will show how much time you have used, but you have unlimited time. Click on the “Finish Exam” button at the end when you are done. The number correct, number wrong, and number skipped will be displayed at the bottom of the page. Feedback for each answer will also be shown as well as your answer.
You will not be able to change your answers after you hit the “Finish Exam” button.
- y % 1
- Since every value is evenly divisible by 1 this will always return 0.
- y % 2
- This will return two possible values 0 if even and 1 if odd.
- y % 3
- This will return 0, 1, or 2.
- y % 4
- This will return 0, 1, 2, or 3.
- newPixel = image.Pixel(r, g, b)
- This creates a new pixel with the given red, green, and blue values.
- img.setPixel(x, y, newPixel)
- This updates the pixel values in the image at x and y with the colors in the pixel.
- p = img.getPixel(x, y)
- This gets the pixel at the given x and y location.
- win = ImageWin(img.getWidth(), img.getHeight())
- This creates a window that can be used to display the image.
- The program removes all the red from the image
- This would be true if the red was always set to 0.
- The program changes all the red pixels to a single color
- This would be true if the red was always set to the same value.
- The program changes all the pixels to have some red
- If r is less than 120 the red is removed (set to 0).
- The program changes the image to only have 3 values of red
- The red will be sets to 0, 200, or 255.
- Vertical stripes that alternate between red and black and start with red.
- Sue turns left 90 so the stipes are vertical. The first element in range(5) is 0 so the stripes start with red.
- Vertical stripes that alternate between black and red and start with black.
- This would be true if the color was set to black when index is even and red when index is odd.
- Horizontal stripes that alternate between red and black and start with red.
- This would be true if sue didn't turn left 90 degrees at the start.
- Horizontal stripes that alternate between black and red and start with black.
- This would be true if sue didn't turn left 90 degrees at the start and if the color was set to black when the index is even and red when it is odd.
- A random value between 10 and 20
- This would be true if it was random.randrange(10,21)
- A random value between 11 and 19
- This would be true if it was random.randrange(11,20)
- A random value between 11 and 20
- This would be true if it was random.randrange(11,21)
- A random value between 10 and 19
- The randrange function returns a random value between the first parameter value and one less than the second parameter value.
Which of the following expressions gives you 3 possible results for all values of y?
Which of the following statements actually changes the image?
What does the following code do to the image?
from image import *
# CREATE AN IMAGE FROM A FILE
img = Image("arch.jpg")
# LOOP THROUGH ALL PIXELS
for x in range(img.getWidth()):
for y in range(img.getHeight()):
p = img.getPixel(x, y)
r = p.getRed()
g = p.getGreen()
b = p.getBlue()
# VALUES FOR THE NEW COLOR
if r < 120:
r = 0
elif r < 240:
r = 200
else:
r = 255
# CREATE THE COLOR
newPixel = image.Pixel(r,g,b)
# CHANGE THE IMAGE
img.setPixel(x, y, newPixel)
win = ImageWin()
img.draw(win)
What does the following code draw?
from turtle import *
space = Screen()
height = space.window_height()
maxY = height / 2
sue = Turtle()
sue.pensize(10)
sue.left(90)
for index in range(5):
sue.penup()
if index % 2 == 0:
sue.color('red')
else:
sue.color('black')
sue.goto(index * 10, -1 * maxY)
sue.pendown()
sue.forward(height)
What does random.randrange(10,20) return?