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

Fall 2006 Midterm 2 Review

Important

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.

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 and confirm it when its 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.


Review Session

There will be a review session on Monday, October 23rd at 7pm during which these questions will be explained.



1. HTML Fun

1. What does HTML stand for?

2. What is HTML validation and why is it necessary?

3. Match the following HTML tags to its function:


1. <html>
a) Enables you to write Javascripts
2. <a href>
b) Puts an image on your page
3. <img>
c) Used to specify a title for your webpage
4. <head>
d) Makes a table on your webpage
5. <title>
e) Specifies a link to another page
6. <p>
f) The heading is enclosed within these tags
7. <script>
g) Makes a row for your table
8. <table>
h) The entire document is enclosed within these tags
9. <tr>
i) Identifies a paragraph of text

Questions, comments, and answers for Fall 2006 Midterm 2 Review: HTML Fun


2. String Fun


Write out what each of these programs will return.


def change1():
  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 change2():
  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 Fall 2006 Midterm 2 Review: String Fun


3. 101110101101


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 Fall 2006 Midterm 2 Review: 101110101101


4. File Writing

1. Write a function called double() that takes in an integer number. The function multiplies the given number by 2. The result is written to a file called "number.txt". Assume the file does not exist on your computer. You must create it and it can be in any folder on your computer.

2. Assume there is a file "string.txt" on your computer which has some text in it. Write a function called lastOne() which reads the contents of your file and returns the last character of the text. When you open the file, do not worry about the path, just put string.txt.


Questions, comments, and answers for Fall 2006 Midterm 2 Review: File Writing


5. Modules

1. Write a function called media() that has a directory as a parameter. The function should find out all the media files in the directory i.e. it should find the number of files that have the extension .jpg and .wav. Note: There is a difference between .jpg and .JPG, .wav and .WAV, Your function should take care of all possibilities.


Questions, comments, and answers for Fall 2006 Midterm 2 Review: Modules


6. Sound Theory


1. What is the difference between frequency and amplitude?

2. Explain the Nyquist theorem briefly.

3. How many bits are used to represent a sound? What is the range of sample values that a sound can have?

4. What is clipping?


Questions, comments, and answers for Fall 2006 Midterm 2 Review: Sound Theory


7. Sound Coding


1. Write a function called upDown() that has one parameter - a sound. The function should increase the volume of the first half of the sound and decrease the volume of the second half of the sound. Note: It doesn't matter how much the sound is increased or decreased.

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

3. 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 Fall 2006 Midterm 2 Review: Sound Coding


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

Write a function to encode an input string so that some key consonants are replaced with symbols, using this table:

FROMTO
r-
s=
t:

Questions, comments, and answers for Fall 2006 Midterm 2 Review: Encoding and Decoding


9. Hunting for errors


Find the syntax errors and rewrite the functions correctly:
a)
def func1(sound):
  for s in getSample(sound):
    if s > 10000:
      s = 10000
    else:
      s = p
      p = 15000
      print p

b)
def func2():
  f = open("C:\\world.txt", wt)
  f.write("Go Jackets!")
  f.write(13)
  f.close

Questions, comments, and answers for Fall 2006 Midterm 2 Review: Hunting for errors


10. Color codes

1. Represent the following colors in the rgb encoding:

2. Represent the following colors in the hexadecimal format:


Questions, comments, and answers for Fall 2006 Midterm 2 Review: Color codes


11. 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 Fall 2006 Midterm 2 Review: Poking at your hard drive


12. List functions


1. Write a function called addItems() that takes in a list of numbers. The function should return the sum of all the elements in the list.

2. Write a function called rmMid() that takes in a list. The function should remove the middle element in a list. Note: If the list has 5(odd) elements, remove the 3rd element. If the list has 4(even) elements, remove the 2nd one.


Questions, comments, and answers for Fall 2006 Midterm 2 Review: List functions


13. String stuff


1. Write a function called countAs() that takes in a string. The function should return the number of occurrences of the letter 'a' in the string.

2. Write a function called countVowels() that takes in a string. The function should count the number of times a vowel occurs and return the answer. Note: Vowels are a, e, i, o, u - just in case anyone forgot.


Questions, comments, and answers for Fall 2006 Midterm 2 Review: String Stuff


14. Address Book


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:

Questions, comments, and answers for Fall 2006 Midterm 2 Review: Address Book
Don't sweat this one at this late stage. It is a good exercise for your critical thinking and approach to programming, but it is more complex than anything that will appear on this midterm. Bobby has posted a solution on the questions page. Colin Potts




15. List Output


What is the output when you run the following function in JES?

def listIt():
  list = []

  for i in range(1, 11, 2):
    list.append(i)

  string = "cHEcK"
  for index in range(len(string)):
    if string[index].isupper():
      list[index] = string[index]
  
  print "The string is", string
  print "The list is", list


Questions, comments, and answers for Fall 2006 Midterm 2 Review: List Output

Link to this Page