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

Spring 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.


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 Spring 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")



Questions, comments, and answers for Midterm Exam 2 Review Spring 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 Spring 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 Spring 2006: Tracing the printing 2



Compute the grade


Students in a hypothetical class have three exams. Exam 1 and Exam 2 are midterms that together are worth 40% of the final grade weighted equally. Exam 3 is the final exam that is worth 60% of the final grade.

Write a function called finalGrade that takes in the three exam scores as parameters and computes the final score. You should print the final score, and print the grade as follows:

If the final grade is:the computer should print:
>=90 Congratulations, you got an A!
>=80 and <90You got a B.
>=70 and <80You got a C.
>=60 and <70 You got a D.
<60Uh-oh.

Questions, comments, and answers for Midterm Exam 2 Review Spring 2006: Compute the grade

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 Spring 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 Spring 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 Spring 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:

FROMTO
r-
s=
t:

(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 Spring 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 Spring 2006: Count 'em up 2


The Cover-Up


You have just been caught by the FBI for downloading illegal music. During your questioning though, you are left with the laptop that contains all the incriminating evidence. There are hundreds of log files in a single directory with your initials in the files. You need to replace all instances of your initials with your TA's initials to throw the FBI off your case.

Remembering what you learned about listing jpeg files in a directory from hw4 (or atleast what you're about to remember):
import os
...

for file in os.listdir(directory):
  if file.endswith(".txt")
    ... perform operations on the current text file

...and remembering how to open files for reading and writing:

myfile = open(fileNameAndLocation, "rt") #open file for reading
myfile = open(fileNameAndLocation, "wt") #open file for writing, clearing the contents of the file


...you must write a function coverUp that takes in a directory name and replaces all instances of your initials in any ".txt" files.

Be sure to close the files that you open!

Questions, comments, and answers for Midterm Exam 2 Review Spring 2006: The Cover-Up


Address book functions


Let's imagine that you have an address book file, named "address.txt", conveniently located in your JES folder (hint: You don't need a path to the file!) The format of the file looks like this:
Charlie Brown:1919 Peanuts Lane:Atlanta, GA:404-992-9292
Peppermint Patty:2020 Cashew Street:Atlanta, GA:404-299-2929
Calvin:101 Tiger Lane:Decatur, GA:770-899-8989


You are to write two functions:
Feeling l33t? Try this...


Questions, comments, and answers for Midterm Exam 2 Review Spring 2006: Address book functions


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:

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 Spring 2006: Poking at your hard drive

Fun with HTML


  1. How does <title> differ from <h1>?
  2. What information goes between <html> and </html>?
  3. What information goes between <body> and </body>?
  4. What information goes between <head> and </head>?
  5. 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 Spring 2006: Fun with HTML

Links to this Page