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 PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Test 3 Review Questions- Spring 2008

Questions?


Will we be filling in the blanks in the code on the test or writing it on our own?
The code will either be fill in the blank or write it based on sample code that we give you. Thanks! Brittany Duncan

Can you please post a review similar to the ones from the past two tests? They are VERY helpful!!
That is the part that will be updated when we design the test. There will be practice problems posted by Thursday afternoon, so they will be available before the review session. Make sure that you look at the old reviews for more general practice problems. Thanks! Brittany Duncan

when you make the normalize(sound) function why do you say largest = 0 in line 2? and does it matter if you learn to normalize using max instead of using if(or vice versa)? is one better than the other?
On line 4, we use
largest = max( largest, getSample(s) )
which will set the new value of largest to getSample(s), only if that sample is larger than 'largest'. We set largest to 0 initially because if we don't, you will get an error, "largest - Name not found globally" the first time through the loop when trying to compare the value of largest to the current sample. We set it to 0 because any sample value in the sound should be equal to or greater than 0 - Ideally we would take the absolute value with
abs( getSample( s ) )

The max function essentially uses if statements to determine which is larger. Either are acceptable, but max is just less code to write. -Buck Scharfnorth

in the makeChord function in the delayed sounds powerpoint, line 3 says:
s1Sample=getSampleValueAt(sound1,index)

what does index mean in this case?
Index is coming from the for loop. You are looping through every possible location in the sound (each sample location), and so index holds that location, 1 - the length of the sound. Chris Phillips



Does the import of a module have to be inside the function that we need it for (like in the examples of random.shuffle on the slides and code page), or can it just be somewhere above the function and/or command using one of the module functions? thanks
The import of a module can be before the def statement or inside the function, it doesn't really matter. Thanks! Brittany Duncan
As long as the module is imported, before your code tries to reference something from that module, it will work. If you try and, say, call os.sep, before you've imported the os module, you will get an error. Chris Phillips

One of the questions on the review asks to count the number of jpg files in a directory and print the results. How would you do that? thanks
You would need to find all the files in the directory using os.listdir(). Then you could go through the resulting list testing whether the file name endswith ".jpg". Each time you find one that does, you increment a running total (which you previously must initialize to zero) by one. Colin Potts

in the ajc temperature code, what do these lines mean
temperature = page[position-2:position]
time = page[position+40:position+51]

The first line extracts a substring that goes from two characters before the current position up to but not including the current position. (The current character position is at this point the one occupied by the degree symbol, so temperature is therefore the two-digit number string preceding the degree symbol.) The second line does something similar for the time. These numbers (40 and 51) just happen to work because of the way the AJC weather page is constructed right now. There's nothing special about them other than that. Try viewing the source of that page, searching for the code for the degree symbol and then count off the number of characters up to the time. Colin Potts


I won't be here Friday... When can I make up the Test?
If you have a documented excused absence or have already cleared this with Monica or me, contact Brittany immediately to schedule the make-up test. Otherwise you can't make it up and will get a zero. The exam dates were posted at the beginning of the semester. Colin Potts

One review question asks us to write a function that adds all the numbers in a list and returns the sum. How would you do that?? Thanks.
Why the double question mark? This is difficult?? You use a loop to go through a list of numbers. Before the loop you initialize a running total to zero. Inside the loop you add the current list item to the running total. When the loop finishes, your running total has become the grand total. You're welcome. Colin Potts

for finding the number of .jpg in a folder, how do you increment a running total. How do you increase the count from 0 by 1 for every .jpg it finds?
Try something like num=num+1 or, as a shorthand, num += 1. This only increments the value from zero to one if the value happens to be zero to start with; in general it makes it one larger than whatever it currently is and is a basic step involved in counting things. You will find examples of incrementing inside loops in most of the programs posted on sound and string processing. If you knew this already (and I hope so) and your question is about how you increment the count only when a jpg file is found (as opposed to for every file in the directory), well, you put an if inside the loop to check that the file is a jpg (see a previous answer about this), and you do the incrementing inside the if. Colin Potts

Monica told us to know how to copy every other sample. How would you do that?



Link to this Page