Summer 2006 Midterm 2 Review
Note: The idea of this review is not to tell you exactly what is going to be on the test but to demonstrate concepts that may appear on the upcoming exam. Although we try to comprise all topics, there is a possibility that other topics covered in class and not on this review will be included on the exam
Please try these questions! Post your answers, questions, comments, and concerns 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 can give hints, and we're glad to respond to partial guesses.
- 80% of the TA's are not robots so it may take a while to get a response. Please be patient. Especially if you post in the wee hours of the morning.
- All questions highlighted in blue are a bit trickier. They aren't all that necessary for the test, but if you can solve them, then you know you're doing well.
- These review questions in general are harder than the test.
Lower or Louder
Consider these two programs:
(a)
def sound1():
snd = makeEmptySound(3)
value = 0
for i in range(1,getLength(snd)):
posn = i % 100
if posn < 25:
value = value + 100
if 25 < posn < 75:
value = value - 100
if posn > 75:
value = value + 100
setSampleValueAt(snd,i,value)
play(snd)
return snd
b
def sound2():
snd = makeEmptySound(3)
value = 0
for i in range(1,getLength(snd)):
posn = i % 200
if posn < 50:
value = value + 200
if 50 < posn < 150:
value = value - 200
if posn > 150:
value = value + 200
setSampleValueAt(snd,i,value)
play(snd)
return snd
(1) Which of these two produces a louder sound?
(2) Which produces a lower sound?
(3) What is the frequency of each sound? (The sampling rate of an empty sound is always 22050 Hz)
(4) What is the maximum amplitude of each sound?
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: Lower or Louder
Sound Timing Questions
(a) How would you figure out the index of where the third second starts in a sound?
(b) Write a program that takes a sourceSound and a targetSound as input, then copy the sourceSound starting at 1 second and ending at 1.5 second into the targetSound starting 2 seconds into the targetSound.
(c) Write a program where you move one second of an input sound from the 4th second of the sound to the start of the 2nd second.
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: Sound Timing
Whoooo! Look at that text go!
What is the tickertape doing?
Which way does the text move?
How many frames are created?
What do the frame names look like?
def tickertape(directory, string):
for frame in range(100):
canvas = makePicture(getMediaPath("640x480.jpg"))
x = frame * getWidth(canvas) / 100
y = abs(50 - frame) * getHeight(canvas) / 100
addText(canvas, x, y, string)
num = str(frame)
if len(num) == 1:
num = '0' + num
writePictureTo(canvas, directory + '//frame' + num + '.jpg')
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: WhooooOOOooo
Movie Code Fragment
Remember this part of the movie generation code?
def writeFrame(num, directory, framepict):
framenum=str(num)
if num < 10:
writePictureTo(framepict, directory + "//frame00" + framenum + ".jpg")
if num >= 10 and num < 100:
writePictureTo(framepict, directory + "//frame0" + framenum + ".jpg")
if num >= 100:
writePictureTo(framepict, directory + "//frame" + framenum + ".jpg")
- What does it do?
- Why is it needed?
- Can you write something shorter?
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: Some Movie Code
What this do?
Consider the below program:
def pharaoh(collardGreens, friedOkra):
for i in range(1, friedOkra + 1):
keke = ''
for banana in range(i):
keke = keke + collardGreens
print keke
for i in range(1, friedOkra):
keke = ''
for banana in range(friedOkra - i):
keke = keke + collardGreens
print keke
What happens when you pass a string in for collardGreens and a positive integer for friedOkra?
Try to figure this out without using JES.
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: What this do?
Tracing the printing
def newFunction(a, b, c):
print a
list1 = range(1, len(c))
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 you see?
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: Tracing the printing 2
String Fun
Write out what each of these programs will return.
def thingamabob():
source = "Georgia Institute of Technology"
vowels = "aeiou"
source = source.lower()
for i in vowels:
loc = source.find(i)
if loc <> -1:
source = source[:loc] + source[loc + 1:]
return source
def thingamajig():
source = "Georgia Institute of Technology"
vowels = "aeiou"
source=source.lower()
for i in vowels:
loc = source.find(i)
while loc <> -1:
source = source[:loc] + source[loc + 1:]
loc = source.find(i)
return source
If you don't know what a while loop is, it basically works the same way as an if statement. If the logical statement after the word while is true, then the code below it will run. The only difference is once it's done with the indented code, it'll go back to the while statement and check to see if it's true again. If it is, then it'll do it again. So whenever you see a while statement, think "while this statement is true, do this...". While Loops will not be on the midterm, but you may find other concepts from this question beneficial to your review. For more information about the wonderful word of while loops, see page 240 in the book.
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: String Fun
Short Novel
(a) Give one example of a task for which you would not write a program.
(b) Give another example of a task for which you would write a program.
(c) What is dot notation and when do you use it?
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: Short Novel
001110100010110100101001
For each of the below, see if you can figure out the representation in terms of bits and bytes.
(a) Internet addresses are four numbers, each between 0 and 255. How many bits are in an Internet address?
(b) In networking, computer port numbers range from 1 to 65,536. How many bits are needed to represent a port number?
(c) Each pixel's color has three components: red, green, and blue, each of which can be between 0 and 255. How many bits are needed to represent a pixel's color?
(d) A string in some systems can only be up to 1023 characters. How many bits are needed to represent the length of a string in such a system?
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: 001110100010110100101001
Encoding and Decoding
Remember the string method replace()?
>>> letter = "Mr. Mark Guzdial requests the pleasure of your company at..."
>>> print letter.replace('a','!')
Mr. M!rk Guzdi!l requests the ple!sure of your comp!ny !t...
>>> print letter.replace('a','!').replace("e","#")
Mr. M!rk Guzdi!l r#qu#sts th# pl#!sur# of your comp!ny !t...
(a) Write a function to encode an input string so that some key consonants are replaced with symbols, using this table:
(b) Write a second function that takes an encoded string as input, and returns the original unencoded string with the consonants restored.
(c) Write a function that replaces all the a's with b's and replaces all b's with a's
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: Encoding and Decoding
Count 'em up
(a) Write a function called countAs that will take a string as input. Count the number of a's in the input, and return (but not print) the count.
(b) Now, write a function to count the a's and e's, and print out both counts.
(c) Write a function that will tally up all letters and print out totals for each. It is possible to do this without 26 if statements.
Hint: Sometimes strings go through an identity crisis and act like lists. That means you can use them in for loops like this.
>>> for i in "Hello":
... print i
...
H
e
l
l
o
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: Count 'em up 2
Poking at your hard drive
Consider the following code that was run in the command area of JES...
>>> import os
>>> folder = pickAFolder()
>>> files = os.listdir(folder)
>>> file = files[0]
>>> foo = file.rfind('.')
>>> bar = file[foo:]
Assuming that a valid folder was chosen with pickAFolder() and there was atleast one file in it, which of the 4 types (number, string, list, object) are the following:
- folder
- files
- file
- foo
- bar
What sort of information would you expect to learn if you were to run the following command next?
>>> print bar
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: Poking at your hard drive
Fun with HTML
- How does <title> differ from <h1>?
- What information goes between <html> and </html>?
- What information goes between <body> and </body>?
- What information goes between <head> and </head>?
- What would you find inside the <html> and </html> but not surrounded by <body> or <head> tags?
Questions, comments, and answers for Midterm Exam 2 Review Summer 2006: Fun with HTML
Link to this Page
- Hotspots #3 last edited on 5 May 2008 at 10:40 am by c-76-17-124-0.hsd1.ga.comcast.net