Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

This page removed for FERPA compliance
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 1 Review Fall 2005: 20 Questions


I am having difficulty understanding range. Why does range print [1,4,7] when you ask it to print range(1,10,3)?
range(1, 10, 3) means start at one, stop before you get to 10, and increment by 3.
[1 + 3 * 0, 1 + 3 * 1, 1 + 3 * 2]
-Student1680

Question #3 asks: What does the statement: for x in range(1,50): do?
Is this the answer: the variable x is taking on the value of 1 and the width is 50?
Thanks.
The variable x represents each item in the list one by one as the code below it is run. -Student1680

is the rule or thumb for colons just that it should be at the end of the beginnng line of a block?

Yes. That's how they relate. But when do you know when to use an indented block? -Student1680

how does a for loop work iteratively?
take this code snippet for example
for p in getPixels(picture):
  do stuff
getPixels is actually a list of pixels. p represents each one of those pixels one by one. If there's a million pixels, then the "do stuff" below it executes a million times doing something to each one of those pixels. This is different from the common misconception that it magically does everything at once. -Student1680

are 'take - in' and 'take on' generally the same thing? (input value is assigned to the input variable)

As far as "take in" and "take on" go, the action is the same. The difference is in who's doing what. A function "takes in" a value. A variable in the function "takes on" a value from the function "taking it in". -Student1680

I am not sure how brightness is different from luminance. I wrote down in recitation that we are able to manipulate luminance, and that it has a weighted value or something. I wrote down that brightness changes all of the values at the same time. I'm not sure what either of those mean. Any help?

Yellow is 255,255,0.
Purple is 255,0,255
Obviously yellow APPEARS lighter than purple. But the brightness is the same when you average all the numbers. Luminance is your PERCEPTION of the brightness. Yellow has a higher luminance than purple but the same brightness. -Student1680

"print" prints a filename but doesn't save the input to be used again
"return" allows the input to be used in another function/program

Your definition for print is a wee bit too specific. -Student1680

"print" prints the variable but doesn't save it to be used again

good Student1919

In question 1, what happens when you type in someREMOVEDnction(2, 'fred')? Does it evaluate a function with variables 2 and 'fred'?


Yes. Where x is now 2 and y is now the string 'Fred'. -Student1680

  1. 7
:RGB takes up 3 bytes of information, which has a limit of 24 bits, and yes there are enough colors representable in RGB?


Yes. -Student1680

when returning a value, a block of code will "return" a value to the larger function for use, which also serves to print the value on occasion?

is the answer to question 3. . . it gives values 1-49 to be manipulated within the "for" loop of the function.

my brain hurts
Sorry to hear that. -Student2081

What is the general rule for colons?
colons are followed by def, for and if. It means that something is going to follow one of these statements -Student2081

Why is there a max of 255 to a color channel? Is it because there's 8 bits per color component, and using only 0's and 1's, you calculate 2^8 which is 256....256 being 0? Or did I...just make that up?
Correct -Student2081

what is hierarchial decomposistion,
It is when you break up a complex program into smaller REMOVED managable parts. This makes it easier to find the reason for an error message -Student2081



Link to this Page