Practice BlueBook Quiz 1 Solutions

For most problems there are several correct answers. Important: We stronly encourage you to attempt all of the problems before looking at the solutions. It is much easier to recognize a correct answer than to come up with one.

1. Bit

  
def diagonal_line(filename):
  bit = Bit(filename)
  bit.paint('blue')
  while bit.front_clear():
      bit.move()
      if bit.front_clear():
          move()
          bit.left()
          bit.move()
          bit.paint('blue')
          bit.right()
  

2. Images

  
def bottom_stripe(filename):
    image = SimpleImage(filename)
    out = SimpleImage.blank(image.width, image.height + 10)
    for y in range(image.height):
        for x in range(image.width):
            pixel = image.get_pixel(x, y)
            pixel_out = out.get_pixel(x, y)
            pixel_out.red = pixel.red
            pixel_out.green = pixel.green
            pixel_out.blue = pixel.blue
    for y in range(10):
        for x in range(image.width):
            pixel_out = out.get_pixel(x, y + image.height)
            pixel_out.red = 0
    return out
  

3. Strings

  
def reverse(s):
  output = ''
  for i in range(len(s)):
    output += s[len(s)-1-i]
  return output