 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Midterm Exam 1 Review Spring 2003: Generalized changeRed
Try the problem here from Sp 2003 Midterm Review #1
So we are supposed to write out programs on paper for our exam?? This is scary....!
| REMOVEDp, you will. This class is still about programming – it's not easier than 1321, it's different than. I recommend trying the midterm exam review problems – the midterm exam problems are quite similar. Practice here over the next week and a half, and you'll be in good shape for the midterm Mark Guzdial |
Do we need to include all three changes in our program as well as pickAFile, or will that be something that would be done in the command area? ie. Do you wnat soemthing like this?
def changeRed(pict):
file =pickAFile()
pict =makePicture(file)
show(pict)
for p in getPixels(pict):
setRed(p,getRed(p)*-.10)
setRed(p,getRed(p)*.30)
setRed(p,getRed(p)0)
repaint(pict)
No, that's not the idea. You're to write a single function, like increaseRed or decreaseRed. You don't do pickAFile, nor makePicture, nor show, nor repaint. And you don't accept a single input, you accept TWO inputs – like what we discussed in class this morning. Finally, you're not doing JUST -.10, .30, and 0. Instead, write a function to handle ANY change factor.
Here's a hint. If you want to increase the red by 50%, what do you multiply the red component by? 1.50 = 1.0 + .50. If you want to decrease the red by 25%, what you multiply the red component by? 0.75 = 1 - .25. Mark Guzdial
This is what I got. Same for everyone else?
def changeRed(pict,x):
for p in getPixels(pict):
setRed(p,getRed(p)*(1+x))
I got roughly the same function and it tested to be right I believe when I ran it (or at least a similar version using pickAFile instead)
That's cool. I dunno if he'll count off, but he said higher up on this page that we shouldn't use pickAFile, makePicture, or any of that jazz.
| Names? Anybody got any names here? Program is missing an important operation in the expression. Mark Guzdial |
I rewrote the program slightly differently. I tested it and it worked.
def changeRed(picture,x):
for p in getPixels(picture):
value=getRed(p)
setRed(p,value * (1+x))
Rebecca
Oops! when I posted it, it didn't put in the spaces. I can't seem to figure out how to post with the spaces. But, I have spaces before the "for" loop and extra equal indents before the "value" and "setRed" lines.
| (a) Start each line with "=", or, (b) put <html><pre> before the code, and </pre></html> after it Mark Guzdial |
By the way, the program that was missing something was missing the asterick between the "(p)" and the "(1+x)". Also, there isn't an asterick in the last program between "value" and "(1+x)". I think that the astericks aren't always displaying on the pages.
| Bingo. You can use ☆ to make sure that asterisks show up, or use the html-pre technique I mention above. Mark Guzdial |
REMOVEDw do you fill in the value for x when you want to run the program? I've tried assigning x a value in both the top and bottom areas, but neither is working for me. Thanks
| Try changeRed(pict,.30) – or any of the other examples on the exam review REMOVED Mark Guzdial |
Where can I get the definitions for the commands in part 2 of the midterm review? I have "def" from page 32 of the book, but I am still thumbing through to find the others. If anyone can help that would be great!
What "part2" are you referring to? Are you talking about the review problem "What does it mean?"? Do you need help with understanding that "for" has to do with loops and "print" displays something on the page?
"for" page 64
"print" page 23
Student116
There's also an index in the book. Anybody tried the Help functions in JES?
stupid question...why is it (1+x) and not just x?
Kelly Farrell
Well, initially I put in mine because Prof. Guzdial put a posting up at the top about it that way. REMOVEDwever, my understanding is that because your function is just to "change" red, this doesn't include whether to increase or decrease red. To increase or decrease red (or any color for that matter) you have to either add to or subtract from 100%. If we use just "x", whoever uses the code has to perform this operation (adding or multiplying) in their head in order to input the correct value. The "changeRGB" program is much easier to handle when treated with "1+x".
Student116
| We certainly could do it the way Kelly describes – then the input would just be the multiplier. Rebecca's right, though – this way, the input is the amount and direction of change. Mark Guzdial |
Link to this Page