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

Midterm Exam 1 Review Fall 2003: Check your luminance

(Back to Fall2003 Midterm Review 1)

Answers? Comments? Comments on answers?


def checkLuminance(r,g,b):
  newRed = r * 0.299
  newGreen = g * 0.587
  newBlue = b  0.114
  luminance = newRed + newGreen + newBlue

  if luminance < 10:
    print "That's going to be awfully dark"

  if luminance > 50 and luminance < 200:
    print "Looks like a good range"

  if luminance > 250:
    print "That's going to be nearly white"
    

We aren't sure about the 'and', that's very sketchy.

'and' works in the way you have described it to link conditions in 'if' statements. -Stephen Voida

Is it the missing < again?

I fixed it. See the FAQ page for how to enter code into the CoWeb. Mark Guzdial


do you need to include int in the program??
int(r*0.299)

Excellent question! Turns out not to be the issue – the color functions will do the int() for you. Mark Guzdial


is a for loop not needed in this question. if so, why not?

how do you call this function in the command area? Also, there is an asterisk missing after the b in the newBlue statement.

You would call the function by typing checkLuminance(and three pixel values) in the command area. ie. you could enter checkLuminance(255, 255, 255) to have That would be nearly white returned. A for loop is not necessary in the example above because whereas you have been nomally using for loops to check specific pixels of a picture, in this function the pixel is already specified (because you enter the pixel values as input rather than a whole picture.



If i understand correctly, we DONT have to worry about the "newRed = int(r .299)"?
all we need is

newRed = r * .299

sorry forgot the * in there...

Try it! Mark Guzdial
>>> x = getPixel(mypicture,10,20)
>>> print x
Pixel, color=color r=118 g=160 b=220
>>> setRed(x,34.56)
>>> print x
Pixel, color=color r=34 g=160 b=220



I keep getting the following error: Your code contains at least one syntax error, meaning it is not legal jython.
The error is on line 4

def checkLuminance(red, green, blue):
  luminance = (red*0.299) + (green*0.587) + (blue  0.114)
  if (luminance < 10):
    print ?That?s going to be awfully dark?
  if (luminance > 50) and (luminance < 200):
    print ?Looks like a good range?
  if (luminance >250):
    print ?That?s going to be nearly white? 


Go back and make sure you have that all entered correctly (check your HTML) because the way it is showing up right now, I can see a couple of problems, but I think they might just be HTML related. Summer McWilliams

Never mind- I had copied the function from Word where I was working on it. The statements in quotations weren't red. I just retyped them.


do we need to add "print luminance" in here anywhere so that we actually get the luminance value back?
You only have to have it print what the question asks to have printed. In this case it asks for the phrases, so no you don't have to add it in. Summer McWilliams

what is the difference in using "or" as opposed to "and" when you have a range like "between 50 and 200"??
In this example, you would use and is for values that must be inbetween a certain range, that is the overlap of two larger ranges (ie. when luminance is greater than 50 and less that 200, so it's between 50 and 200). Or is used for the reverse case, when the the value only has to be located in one range (ie. when the luminance is greater than 200 or less than 50, so the two do not overlap). Summer McWilliams

For between 50 and 200, would you not also add one equal signs to the syntax? i.e. 50 is between 50 and 200.

You can use an equal sign if you want to include 50 and 200, but it is not specified in this questions, so I think both ways would be acceptable answers. Brittany Selden




Link to this Page