Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Excersise Set 2 (Part 2)

Here are some more excersises to help you with your code tracing.

Part 2 Answers
If the original picture looks like this External Image,

Match these pictures to the code that created them when it was run on the original picture.
(A) External Image (B) External Image (C) External Image(D) External Image (E) External Image

(1)
def changeColorSquares(file):
  picture = makePicture(file)
  show(picture)

  for pixel in getPixels(picture):
    r = getRed(pixel) 
    g = getGreen(pixel)
    b = getBlue(pixel)

    average = (r + g + b)/3
    new_color = makeColor( average, average, average )
    setColor(pixel, new_color)

  repaint(picture)

(2)
def changeColorSquares(file):
  picture = makePicture(file)
  show(picture)

  for pixel in getPixels(picture):
    setRed(pixel, 0)

  repaint(picture)

(3)
def changeColorSquares(file):
  picture = makePicture(file)
  show(picture)

  for pixel in getPixels(picture):
    setGreen(pixel, 255)
    setBlue(pixel, 255)

  repaint(picture)

(4)
def changeColorSquares(file):
  picture = makePicture(file)
  show(picture)

  for pixel in getPixels(picture):
    setGreen(pixel, 0)

  repaint(picture)

(5)
def changeColorSquares(file):
  picture = makePicture(file)
  show(picture)

  for pixel in getPixels(picture):
    setRed(pixel, 255)
    setBlue(pixel, 255)

  repaint(picture)


Link to this Page