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

Midterm Review Summer 2004

Summer 2004 Midterm Review #1
Below are questions like those we plan to ask on Midterm #1. There are more questions coming! Check back often! This should get you off to a good start. The exam will consist of 4 or 5 questions like these.

Please do try these questions! Post your answers, questions, comments, concerns, and criticisms on the pages for each question. Those comments, questions, etc. can also be about each others' answers! If someone posts an answer that you don't understand, ask about it! If you see a question here that you know the answer to, don't keep it to yourself – help your fellow students!

We will be reading your answers. Here are the ground rules for the interaction.

If you don't post, neither will we. We will not be posting official solutions to these problems at all! If one of you gets it right, terrific!
We will try to always point out if an answer is wrong. We won't always point out when the answer is right.
We are glad to work with you toward the right answer. We will give hints, and we're glad to respond to partial guesses.

You will be expected to write some code for the exam, but you will not be expected to _remember_ any particular recipe line-by-line. The best thing to do is to make sure that you understand how the recipes you saw on the review work... know how to call various recipes that you have had to use to manipulate pictures, know how to put recipes together (understand what each line means and why it's needed). You'll notice that on the review, you were asked to write some code and you were given some code. The review questions ask for and offer about the same amount of information as the exam questions will. -kk



1. Compute Math Grades


You are creating a tool to be used by TA’s who want to see what final grades their students made. The grade is calculated by adding together 2 quizzes (each one is worth 20% of the student’s grade), 1 midterm (worth 25% of the student’s grade), and 1 final exam (worth 35% of the student’s final grade). The final grade is then (Quiz1 X .2+Quiz2 X .2+Midterm X .25+Final Exam X .35).

Write a function called finalGrade that takes in both quizzes, the midterm, and the final exam. (e.g., def FinalGrade(Quiz1, Quiz2, Midterm, FinalExam)) The function should then compute the student’s final grade. You should print the final grade and print a comment as follows:


If the Final Grade is:The computer should print:
>= 90 Amazing!
>= 80 and <90 Beautifully Done!
>70 and <80 C Ya!
=70 Definitely Finished!
<69Flunked it!

Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: Compute Math Grades




2. Concepts

Explain and give an example (or tell where you might find examples) the following items:

a. Pixel:




b. Array:




c. Manipulating Media:




d. “For Loop”:




e. “If Statement”:




f. Luminance:


Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: Concepts




3. Color/Colour


In class we discussed different ways to write functions that essentially do the same thing. As far as being a good program, some are better than others.

a. Describe what makes some functions better than others:






b. Using the recipes below as an example, write two different functions that can make a picture sepia-toned.

1.  
def makeSunset(picture):
   for p in getPixels(picture):
     value=getBlue(p)
     setBlue(p,value*0.7)
     value=getGreen(p)
     setGreen(p,value*0.7)



2. 
def makeSunset(picture):
   reduceBlue(picture)
   reduceGreen(picture)

def reduceBlue(picture):
   for p in getPixels(picture):
      value=getBlue(p)
      setBlue(p,value*0.7)

def reduceGreen(picture):
   for p in getPixels(picture):
      value=getGreen(p)
      setGreen(p,value*0.7)


Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: Color/Colour #2


4. But what does it do?


a. Consider the program below.
def newProgram(a, b, c, d):
   for i in range (1, c):
       if b >= d:
	 print “Gone Fishin!”
       if b < d:
         print “Gone Huntin!”
       if a > b:
	 print “Gone Shoppin!”
       if a <= b:
	 print “Gone to Bed!”

With the input newProgram(12,56, 7, 63) what will be printed?



b. Consider the program below:
def tryMe2(d,e,f):
  for something in range(1,e/d^2):
    print f
    if something/2.0 == int(something/2.0):
     print "Gotta be Even!"

With the input tryMe2(6, 8, "Dog"), what will be printed?

Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: But What Does it Do?



5. Generalized changeColor


Write a new version of the function increaseRed and decreaseRed (and blue and green) called changeColor that takes as input a picture AND an amount to increase or decrease a color by AND a number 1 (for red), 2 (for green), or 3 (for blue). The amount will be a number between -.99 and .99.


def increaseRed(pict):
  for p in getPixels(pict):
    setRed(p,getRed(p)*1.2)
    
def decreaseRed(pict):
  for p in getPixels(pict):
     setRed(p,getRed(p)*.80)


Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: Generalized changeColor




6. Which does which?


Use the functions below to answer the following questions.
A.
def blueOneHundred(picture):
   for x in range(1,100):
       for y in range(1,100):
           pixel = getPixel(picture,x,y)
           setBlue(pixel,100)


B.
def removeBlue(picture):
   for p in getPixels(picture):
       if getBlue(p) > 0:
           setBlue(p,100)

C.
def noBlue(picture):
   blue = makeColor(0,0,100)
   for p in getPixels(picture):
      color = getColor(p)
      if distance(color,blue) > 100:     
          setBlue(p,0) 

D.
def byeByeBlue(picture):
    for p in getPixels(picture):
       if getBlue(p) > 100:
           setBlue(p,0)

a. Which of the recipes above takes a picture and removes all the blue from every pixel of that picture that already has a blue value of more than 100?

1. A only
2. D only
3. B and C
4. C and D
5. None
6. All

b. Which function(s) set the blue value of the pixel(s) to 100?

1. A only
2. B only
3. B and C
4. A and D
5. A and B
6. None
7. All

c. Which function(s) only analyzes some of the pixels in the picture?

1. A only
2. B only
3. B and C
4. A and B
5. None
6. All


Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: Which does Which?




7. Match the meaning to the program


Here are four possible outcomes of programs:
  1. Mirror the input picture's leftmost 20 pixels to pixels 21 to 40.
  2. Copy the good part of the temple pediment to the broken part.
  3. Copy the broken part of the temple pediment to the working part.
  4. Mirror the input picture right to left
  5. Mirror the input picture left to right

Which of the below programs does which of the above outcomes?

A.
def mirrorTemple():
  source = makePicture(getMediaPath("temple.jpg"))
  mirrorpoint = 277
  lengthToCopy = mirrorpoint - 14
  for x in range(1,lengthToCopy):
    for y in range(28,98):
      p = getPixel(source,mirrorpoint-x,y)
      p2 = getPixel(source,mirrorpoint+x,y)
      setColor(p2,getColor(p))
  show(source)
  return source


B.
def mirrorTemple():
  source = makePicture(getMediaPath("temple.jpg"))
  mirrorpoint = 277
  lengthToCopy = mirrorpoint - 14
  for x in range(1,lengthToCopy):
    for y in range(28,98):
      p = getPixel(source,mirrorpoint-x,y)
      p2 = getPixel(source,mirrorpoint+x,y)
      setColor(p,getColor(p2))
  show(source)
  return source


C.
def mirrorVertical(source):
  mirrorpoint = int(getWidth(source)/2) Tracing the printing
  for y in range(1,getHeight(source)):
    for xOffset in range(1,mirrorpoint):
      pright = getPixel(source, xOffset+mirrorpoint,y)
      pleft = getPixel(source, mirrorpoint-xOffset,y)
      c = getColor(pleft)
      setColor(pright,c)


D.
def mirrorVertical(source):
  mirrorpoint = int(getWidth(source)/2)
  for y in range(1,getHeight(source)):
    for xOffset in range(1,mirrorpoint):
      pright = getPixel(source, xOffset+mirrorpoint,y)
      pleft = getPixel(source, mirrorpoint-xOffset,y)
      c = getColor(pright)
      setColor(pleft,c)


E.
def mirrorVertical(source):
  mirrorpoint = 20
  for y in range(1,getHeight(source)):
    for xOffset in range(1,mirrorpoint):
      pright = getPixel(source, xOffset+mirrorpoint,y)
      pleft = getPixel(source, mirrorpoint-xOffset,y)
      c = getColor(pleft)
      setColor(pright,c)


Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: Match the meaning to the program


8. Scaling with input


Consider the below program:
def copyBarbsFaceScaled(factor):
  # Set up the source and target pictures
  barbf=getMediaPath("barbara.jpg")
  barb = makePicture(barbf)
  canvasf = getMediaPath("7inX95in.jpg")
  canvas = makePicture(canvasf)
  # Now, do the actual copying
  sourceX = 45
  for targetX in range(100,100+int((200-45)*factor)):
    sourceY = 25
    for targetY in range(100,100+int((200-25)*factor)):
      print "Copying from ",sourceX,sourceY," to ",targetX,targetY
      color = getColor(getPixel(barb,int(sourceX),int(sourceY)))
      setColor(getPixel(canvas,targetX,targetY), color)
      sourceY = sourceY + (1.0/factor)
    sourceX = sourceX + (1.0/factor)
  show(barb)
  show(canvas)
  return canvas


A. What pictures will appear when you execute copyBarbsFaceScaled(0.5)? What will be the first four lines printed?

B. What pictures will appear when you execute copyBarbsFaceScaled(2.0)? What will be the first four lines printed?

C. What pictures will appear when you execute copyBarbsFaceScaled(1.5)? What will be the first four lines printed?

Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: Scaling with input


9. Tracing the printing


def newFunction(a, b, c):
    print a
    list1 = range(1,5)
    value = 0
    for x in list1:
        print b
        value = value +1
    print c
    print value


If you call the function above by typing:
newFunction("I", "you", "walrus")
what will the computer print?

Hint: DON'T TRY IT IN JES! Try to figure it out by walking through the code. On the exam, you will NOT have access to JES.

Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: Tracing the printing


10. Manipulate an array


Write a function dup100 to input a sound filename and return the sound where the first 100 samples are duplicated. Let's say that the original sound's samples look like this for the first five samples "54,62,-13,-2,4..." Then the output sound's first ten samples should look like this "54,54,62,62,-13,-13,-2,-2,4,4..." Thus, the output's first 200 samples will be different from the original (the first 100 duplicated), but the rest of the samples will be the same.

Questions, comments, and answers for Midterm Exam 1 Review Summer 2004: Manipulate an array

Link to this Page