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

Summer 2005 - Exam 1 Review Questions

If you have any confusions or questions about any of the questions, please feel free to post them to the corresponding question pages. A TA will answer your question as soon as possible, but please refrain from posting full-answers.

Data types


Discuss the differences amongst the following:
Which of the above types do each of the following fall under?

Data Type Questions



Write a Function



Write a function called adjust that takes in a picture and decreases the red in that picture by 50%

Now modify that function so that it takes in a picture AND a number that is a ratio and modifies the red in that picture by that ratio.
So for example...
>>> adjust(somePicture, .8)

...would reduce the red in somePicture so that it was 80% of its previous value.

Write a Function Questions



The Most Important Conceptual Question


What is the difference between print and return?

Print vs. Return Questions



Data In/Data Out



Data In/Data Out Questions



What Happen?


Suppose p is a pixel...
>>> setRed(p, 300)
>>> print getRed(p)


>>> print 5 / 2


>>> print 5 / 2.0


>>> getPixels(pic)


>>> 4 < 2


Suppose p is a pixel...
>>> setColor(p, white)
>>> setRed(p, 0)
>>> setBlue(p, getRed(p))
What color is the pixel now?

What Happen? Questions



More Short Answer



More Short Answer Questions



Tracing Fun!


What do the following functions do?


def tomato(pictureA, pictureB):
  for x in range(1, getWidth(pictureB) + 1):
    for y in range(1, getHeight(pictureB) + 1):
      targetPixel = getPixel(pictureA, x, y)
      sourcePixel = getPixel(pictureB, x, y)
      color = getColor(sourcePixel)
      setColor(targetPixel, color)



def cucumber(picture):
  for p in getPixels(picture):
    color = getColor(p)
    if distance(color, white) < distance(color, black):
      setColor(p, white)
    else:
      setColor(p, black)


def hashbrowns(number):
  foo = 0
  for i in range(number + 1)
    foo = foo + i
  return foo


def nothingPolitical(picture):
  for xoffset in range(1, getWidth(picture) / 2):
    for y in range(1, getHeight(picture) + 1):
      liberal = getPixel(picture, xoffset, y)
      conservative = getPixel(picture, getWidth(picture) - xoffset, y)
      colorA = getColor(liberal)
      colorB = getColor(conservative)
      setColor(liberal, colorB)
      setColor(conservative, colorA)


Tracing Questions


Link to this Page