![]() ![]() |
| |||||||||
| Hotspots: Slides and Code TA Corner Comments? Announcements FAQ Static Webspace | ||||||||||
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| The code will either be fill in the blank or write it based on sample code that we give you. Thanks! Brittany Duncan |
| 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 |
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 |
| 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 |
| 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 |
| 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 |
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 |
| 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 |
| 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 |
| 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 |