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

Final Exam Review- Spring 2008

Please make sure to review your tests and understand why you lost points on problems, as well as how you would complete those problems if you were to see them again. Also realize that concepts that have not been tested yet will be emphasized on this exam.

Programming basics

EXAMPLE QUESTION: If you type the following into the command area of JES, what will be printed on the line below?

(a) 5.0/2
(b) 5/2
(c) getHeight(makeEmptyPicture(640, 480))
(d) distance(green, green)
(e) distance(black, blue)
(f) range(0, 3)

EXAMPLE QUESTION: Please write what would be printed if you typed the follwing in the JES command area.

(a) 13 / 2
(b) 2 1
(c) 2 == 2
(d) 1 == "1"
(e) 13 % 2

EXAMPLE QUESTION: Consider this code and fill in the blanks below:
for x in range(0,1000):
	print x # First command
print x #Second command

(a) The number of times the first print command is executed: ...........
(b) The number of times the second print command is executed: ..........

Pictures


EXAMPLE QUESTION: The maximum value that can be represented by a byte is....

EXAMPLE QUESTION: How many bytes are used to represent an RGB color?

EXAMPLE QUESTION: What is the maximum value that can be represented in a byte (e.g. a red, green or blue value)?

EXAMPLE QUESTION: Complete the following to make a shade of gray:shadeOfGray = makeColor(200, 200, _____)

EXAMPLE QUESTION: Which is which?
Yellow (255, 255, 255)
White (0, 0, 0)
Dark blue (0, 0, 64)
Black (255, 255, 0)

EXAMPLE QUESTION: Given the default behavior of JES, if you do the following, what will be printed if you type the following in the command area?

setGreen(pixel, 256)
print getGreen(pixel)

EXAMPLE QUESTION: If pic has dimensions 400x200, how many pixels does pic contain?

EXAMPLE QUESTION: Given the code below and the same picture (pic) as in the previous question,
1 def change(pic):
2   newValue = 255
3   for p in getPixels(pic):
4     setRed(p, newValue)

(a) How many times is line number 4 executed when you enter the command "change(pic)" in the command area?
(b) How many times is line number 2 executed?
(c) If you had another picture called pic2, would typing change(pic2) in the command area instead of change(pic) give you an error message?
(d) After you run the change function on a picture, would you get an error message if you then typed newValue or would you get the value 255?


EXAMPLE QUESTION: Start with the template function transformPicture() on the page Code for transforming pictures. Write the line or lines of code that replace the pass in order to
(a) make a blue channel image (i.e. by zeroing the R and G).
(b) make a orange color negative (i.e. so that it looks like a film color negative). Use a color shift of R+100, G+50 after you have negated the pixel.
(c) make a bitmap (i.e. a black and white posterization, in which a pixel is white if the average pixel value is > 127 or black if it is lower.)

EXAMPLE QUESTION: The Make Sunset question on Test 1 Review- Fall 2007

EXAMPLE QUESTION: Start with the Monochrome function and make a monochrome negative.

EXAMPLE QUESTION: Write a function from scratch that calls Monochrome to make a monochrome negative.

EXAMPLE QUESTION: The Greyscale question on Test 1 Review- Fall 2007

EXAMPLE QUESTION: The Which Does Which? question on Test 1 Review- Fall 2007

EXAMPLE QUESTION: The Generalized Color Changing and Generalized Image Filter questions on Test 1 Review- Fall 2007

EXAMPLE QUESTION: The Check Your Luminance question on Test 1 Review- Fall 2007


EXAMPLE QUESTION: What are the effects on pic of running the following functions? Do not refer to pixels in your answer. Instead, use a word or phrase that describes the overall effect on the picture.

def mystery1(pic):
   for currentPixel in getPixels(pic):
     setRed(currentPixel, getRed(currentPixel)/2)
     setGreen(currentPixel, getGreen(currentPixel)/2)
     setBlue(currentPixel, getBlue(currentPixel)/2)

def mystery2(pic):
   for currentPixel in getPixels(pic):
     setRed(currentPixel, 255-getRed(currentPixel))
     setGreen(currentPixel, 255-getGreen(currentPixel))
     setBlue(currentPixel, 255-getBlue(currentPixel))

def mystery3(pic):
   for pix in getPixels(pic):
     mysteryQuantity = (getRed(pix)+getGreen(pix)getBlue(pix))/3
     setRed(currentPixel, mysteryQuantity)
     setGreen(currentPixel, mysteryQuantity)
     setBlue(currentPixel, mysteryQuantity)


EXAMPLE QUESTION: One form of color blindness is red-green color- blindness. Create a program that generates something like what it's like to see with red-green color-blindness. Write a function redGreenOut which takes a picture as input. For each pixel, set the red and the green values of that pixel to the average of the red and green values. (Hint: You may find mystery3 above a useful starting point for writing code).

EXAMPLE QUESTION: Imagine that you have a tiny picture consisting of just four pixels whose (red, green, blue) values are these:

(10,5,128) (100,0,128)
(2,2,128) (10,10,120)

What will be the (red, green, blue) values in those pixels after running this program?

def cryptic(picture):
   for p in getPixels(picture):
     redVal=getRed(p)
     greenVal=getGreen(p)
     blueVal=getBlue(p)
     newColor=makeColor( redVal/2, blueVal, 64-greenVal)
     setColor(p,newColor)



EXAMPLE QUESTION: The Mangle question on Test 1 Review- Fall 2007

EXAMPLE QUESTION: The Descriptions question on Test 1 Review- Fall 2007


EXAMPLE QUESTION: Using the darken and negate functions on the page Code for transforming pictures, write a function that darkens the top left and bottom right quadrants of a picture and negates the other two quadrants.

EXAMPLE QUESTION: Having solved the previous question, write a function that copies your modified picture onto an empty canvas of the same size and returns the modified picture.


EXAMPLE QUESTION: When a weather forecast is produced using chromakey, with the meteorologist standing in front of a green screen, what would happen if the meteorologist wore green clothes?

EXAMPLE QUESTION: Below is the code that we discussed in class to illustrate chromakey:

def testChromakey():
   colbertFile = getMediaPath("colbert-greenscreen.jpg")
   colbertPic = makePicture(colbertFile)
   weatherFile = getMediaPath("Weather_map.jpg")
   weatherPic = makePicture(weatherFile)

   show(weatherPic)
   bgColor = makeColor(80, 180, 80)
   chromakey(colbertPic, weatherPic, bgColor)
   repaint(weatherPic)


def chromakey(fgPic, bgPic, refColor):
   threshold = 120
   offset = getHeight(bgPic) - getHeight(fgPic)
   for fgPixel in getPixels(fgPic):
     if distance(getColor(fgPixel), refColor) > threshold:
       x = getX(fgPixel)
       y = getY(fgPixel)
       bgPixel = getPixel(bgPic, x , y + offset)
       setColor(bgPixel, getColor(fgPixel))


(a) Describe what happens to weatherPic if you reduce the value of threshold:
(b) Describe what happens to weatherPic if you increase the value of threshold:
(c) Given that this program has the desired effect, why is bgColor defined as having the RGB values (80, 180, 80)? Where do these numbers come from?

Movies


EXAMPLE QUESTION: What are the inputs and the outputs of the MovieMaker tool?

EXAMPLE QUESTION: The earliest movies were shown at 16 f.p.s. (frames per second). Why do current movies, videos and video games have faster frame rates?

EXAMPLE QUESTION: In the Sunset movie, we reduced the blue and green in each pixel on each frame. Why didn't we just increase the red value?

EXAMPLE QUESTION: In the Moving Rectangle Bounces Left-to-Right animation, a new canvas is created at the beginning of the for loop's indented block of code. This seems rather inefficient. Can't we just move that line of code up before the for loop (and unindent it, of course)? What would the animation look like if we did that?

EXAMPLE QUESTION: Consider the code given below, and sketch the frames that are produced when the code is run using the following call. Sketch what is displayed in each frame. (Don’t worry too much about exact accuracy in sizes and positions. Just bear in mind that 25 is one quarter of 100.):

makeTestMovie()

You can assume that writeFrame() is defined to write the frame into an appropriately named and numbered JPG file.
def makeTestMovie():
		for frameNumber in range(1,5):
			frame = makeEmptyPicture(100, 100)
			x = 25 * (4 - frameNumber)
			y = 25 * (frameNumber – 1)
			addRectFilled(frame, x,  y, 25, 25,  black)
			writeFrame(frame, frameNumber)


EXAMPLE QUESTION: Answer the questions based on the function below.
1 def mystery():
2  width = 10
3  rate = 20
4  canvasWidth = 200
5  canvasHeight = 100
6  x = 1
7  y = canvasHeight/2
8  for frameNumber in range(1, 21):
9    canvas = makeEmptyPicture(canvasWidth, canvasHeight)
10   if (frameNumber * rate + 10) < getWidth(canvas):
11      addRectFilled(canvas, x, y, width, width, orange)
12      x = x + rate
13   else:
14      print "Yay"
15      addRectFilled(canvas, x, y, width, width, orange)
16      x = x - rate
17   writeFrame(canvas, frameNumber)


1) When do the frames get written? (Select ONE):
a. All of them get written at the end.
b. One is written each time the program goes through the loop.
c. They don’t get written at all.
d. Only one frame ever gets written: the last one.

2) Assuming that all the frames get written correctly, what does the movie show? (Select ONE):
a. A moving orange square
b. An orange line that grows longer
c. An orange square that grows in size
d. A checkerboard of orange squares

3) How many times does the “if” (line 10) get evaluated?

4) How many times does the block under the “else” (lines 14-15) get executed?

Design, Debugging, and Coding Skills


Sound


EXAMPLE QUESTION: Nyquist’s theorem says that the sampling rate needs to be
A . At least twice the highest frequency in the sound
B. At least half the highest frequency in the sound
C. The same as the highest frequency in the sound
D. 440Hz

EXAMPLE QUESTION: According to Nyquist's Theorem, what is the minimum (i.e. slowest) sampling rate that can be used to represent sounds adequately that contain frequencies up to 16kHz?

(a) 16 frames per second
(b) 8,000 samples per second
(c) 16,000 frames per second
(d) 32,000 samples per second
(e) about 44,000 samples per second

EXAMPLE QUESTION: If you digitized a recording of a mobile telephone conversation and a group of live musicians in a recording studio

(a) Which would require a greater (i.e. faster) sampling rate for
accurate reproduction?
(i) The phone call
(ii) The music recording
(b) Why?

EXAMPLE QUESTION: Given that a sound is encoded as a sequence of two-byte samples, what is the range of values that a sample can have? (The abbreviation "k" means "1,024")

(a) -11..+10
(b) -128..+127
(c) -256..+255
(d) -32k..+32k-1
(e) -64k..+64k-1

EXAMPLE QUESTION:
(a) The sounds in the mediasources directory are all two-byte WAV files. State the maximum and minimum sample values for such a sound. (You can give a value to the nearest thousand.)

(b) Some of the WAV files you may have downloaded or heard demonstrated in class are one-byte sounds. What are the maximum and minimum values for samples in such a sound? (Hint: Answer is not ±11)

(c) What is clipping?

EXAMPLE QUESTION: When we normalize a sound, we make it louder, but we have to be careful not to make it too loud. Explain in English the algorithm for normalizing a sound (Hint: It contains two loops, one after the other).

EXAMPLE QUESTION: Here is a code template for doing something to a sound:
def loopThroughSound1(sound):
   for s in getSamples(sound):
     pass


Suppose that there is a bug in the implementation of getSamples() so that you cannot use it. (In an earlier version of JES this was true.) Rewrite the code template using another way to go through all the samples in the sound. You can assume that getSample() still works correctly.

EXAMPLE QUESTION: The blend function on the Adding two sounds and removing noise from a signal page adds two sounds together. Assuming that s1 and s2 are two sounds What is the difference between (a) and (b) below?

(a)
blend(s1, s2)
play(s1)


(b)
play(s1)
play(s2)


(Hint: What you hear in the two cases is identical, so that's not the difference.)

EXAMPLE QUESTION: White noise is the hissing sound that is often introduced into a recording by equipment, electrical conditions, etc. We can simulate the introduction of white noise into a digitized sound by changing its sample values by random amounts.

Write a short function called makeNoisy that takes a sound as its input and modifies the sound by adding a random amount to every sample. The noise should vary randomly between -500 and +500 in value. Don't worry about the noise causing clipping. Just let that happen (this is noise, after all). You can start from the template below and fill in the details.
import
def makeNoisy(              ):

    for              in                                 :


HTML, Text, and Lists

EXAMPLE QUESTION: HTML is mainly for marking up a document with logical tags. To control the layout and physical appearance of a web page, the best language to use is
(a) CSS
(b) Javascript
(c) Matlab
(d) Python


EXAMPLE QUESTION:

(a) Normally, what would be displayed in blue and underlined in the following text?

<BODY>
<P>This is a fragment of HTML.
<A HREF="anotherPage.html">My favorite colors</A> are navy and gold.
</BODY>

(b) What does this color and underlining indicate to a user?

EXAMPLE QUESTION: Match the following logical document elements with their HTML tags.
(a) Table<A>
(b) Link<H1>
(c) Paragraph<IMG>
(d) Major heading<ITEM>
(e) A row in a table<LI>
(f) A bulleted list<OL>
(g) An item in a list <P>
(h) A picture <TABLE>
<TR>
<UL>


EXAMPLE QUESTION: Here is a function that censors text strings containing references to the University of Georgia.
1 def censor(ugaString):
2  newString = ugaString
3  wordPairs = [["red", "gold"], ["dog", "jacket"], ["Athens",  "Atlanta"]]
4  for wordPair in wordPairs:
5    position = newString.find(wordPair[0])
6    if position != 0:
7      next = position + len(wordPair[0])
8      newString = newString[0: position] + wordPair[1] + newString [next:]
9  return newString

(a) Suppose we execute the following three lines in the command area of JES:

s1 = 'Our campus is in Athens. Our colors are red and black. Go dogs!'
s2 = censor(s1)
print s2

What is printed?

(b) The variable wordPairs is a list. How many elements does it contain?
(i) 0
(ii) 2
(iii) 3
(iv) 6

(c) Suppose the code is running and is executing for loop for the first time. When it gets to line 8, what is the value of len(wordPair [1])?
(i) 0
(ii) 2
(iii) 3
(iv) 4

(d) In line 5, position is
(i) A true or false value (0 or 1)
(ii) An integer
(iii) A string

(e) In line 5, newString is the name of a
(i) module
(ii) string variable
(iii) method

(f) In line 5, find is the name of a
(i) method
(ii) function
(iii) argument

String Practice A
List Practice A


EXAMPLE QUESTION: Write a function that checks whether two strings are equal and returns 1 if they are and 0 if they are not. The function should have the following definition line:

def check(string1, string2):


EXAMPLE QUESTION: Write a function that checks whether two strings have equal lengths and returns 1 if they have and 0 if they have not. The function should have the following definition line:

def check2(string1, string2):


EXAMPLE QUESTION: Write a function that decides whether a string is a palindrome and returns 1 if it is and 0 if it is not. A palindrome is a string which is the same in both directions. The function should have the following definition line:

def palindrome(string1):

So palindrome("notlob") should return 0 and palindrome ("ablewasiereisawelba") should return 1.

Turtles


EXAMPLE QUESTION: Draw the track left by the turtle in the following program. You do not need to draw it perfectly to scale, but show the final position and direction of the turtle.

def mystery():
   world = makeWorld(500, 500)
   turtle = makeTurtle(world)

   penUp(turtle)
   moveTo(turtle, 0, 0)
   turnToFace(turtle, 500, 500)
   penDown(turtle)

   forward(turtle, 500)
   for i in range(4):
     turnLeft(turtle)
     forward(turtle, 50)
   for i in range(3):
     turnRight(turtle)
     forward(turtle, 50)


EXAMPLE QUESTION: Below is a program that has a turtle draw a square with sides of a specified length s.
def square(turtle, s):
   for side in range(4):
     forward(turtle, s)
     turn(turtle, 90)

Using the above code as a starting point, write a program that has a turtle draw a regular polygon with n sides of length s. (Hint: The turtle will have turned through 360 degrees by the time it finishes and will have turned n times.)

Computer Science Topics


EXAMPLE QUESTION: The following program defines a set of animals.
class Reptile:
   def describe(self):
     print "I am a reptile"

class Dinosaur(Reptile):
   def describe(self):
     print "I am extinct"

class Python(Reptile):
   def makeNoise(self):
     print "hiss"


(a) To create a python called monty, what would you type in the JES command area?

(b) Suppose you have python called monty and a dinosaur called barney, what is printed in the command area if you type the following commands? (If an error is generated, just write ERROR).

(i) describe(monty)
(ii) monty.describe()
(iii) monty.makeNoise()
(iv) barney.describe()
(v) barney.makeNoise()
(vi) monty == barney


EXAMPLE QUESTION: In the following recursive function
def factorial(number):
   if number=0:
     return 1
   else:
     return number* factorial(number-1)


(a) Label with an arrow the line or lines of code that constitute the base case.

(b) If the base case were removed so that only the recursive case remained, what would happen to the program when it ran? (Assume that the removal is done correctly and that the resulting program is syntactically valid.)

(c) Underline the recursive call in the code above.


EXAMPLE QUESTION: Make the following text correct by filling in the blanks and circling the correct choices.
For a program written in a high-level programming language like  Python to execute, it has to be translated into 
 ------------------------ for that type of computer. This translation  process can occur in two ways. __________________ 
occurs when the  whole program is translated in one operation and then executed.  __________________ is when the program 
is translated a statement or  line at a time and that part of the program is executed. The [first/second] of these 
approaches results in programs that run faster.  Python is an example of the [first/second] approach. In Jython, which  
we are using in this course, Python is first translated into __________.

EXAMPLE QUESTION: Java is processed by
(a) An interpreter
(b) A compiler
(c) Both
(d) An espresso machine

EXAMPLE QUESTION: Which of the following will affect the speed of a program? (Check all that apply.)
(a) Hardware
(b) Programming language
(c) Algorithmic complexity
(d) Octane content

EXAMPLE QUESTION: The number of steps that the traveling salesman problem must execute for N cities is proportional to
(a) N
(b) N*N
(c) log(N)
(d) N!

EXAMPLE QUESTION: Machine language is
(a) The same for all computers
(b) Unique to a particular type of computer
(c) For a fictitious computer
(d) What Eliza speaks

Questions?

Link to this Page