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 Spring 2003: Check your luminance

Try the problem here from Sp 2003 Midterm Review #1






This is what I got...anybody else?
def checkLuminance(pict):
  for px in getPixels(pict):
    newRed = getRed(px) * 0.299
    newGreen = getGreen(px) * 0.587
    newBlue = getBlue(px)  0.114
    luminance = newRed+newGreen+newBlue
    setColor(px,makeColor(luminance,luminance,luminance))
  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"


Close! Wrong input – read the problem again. It doesn't accept a picture. Mark Guzdial


def checkLuminance (red, green, blue):
  for px in getPixels(picture):
    newRed = getRed(px) * 0.299
    newGreen = getGreen(px) * 0.587
    newBlue = getBlue(px) * 0.114
    luminance = newRed+newGreen+newBlue
    setColor(px,makeColor(luminance,luminance,luminance))
  if luminance < 10: 
    print ?Thats going to be awfully dark?
  if luminance <200 and >50:
    print ?Looks like a good range?
  if luminance >250:
    print "That's going to be nearly white"


def checkLuminance (red, green, blue):
  for px in getPixels(picture):
    newRed = getRed(px) * 0.299
    newGreen = getGreen(px) * 0.587
    newBlue = getBlue(px) * 0.114
    luminance = newRed+newGreen+newBlue
    setColor(px,makeColor(luminance,luminance,luminance))
  if luminance < 10: 
    print ?Thats going to be awfully dark?
  if luminance <200 and >50:
    print ?Looks like a good range?
  if luminance >250:
    print "That's going to be nearly white"


okay i dont know why its not indenting..sorry

I fixed the indentation. Why do you need the for loop? Or the setColor? If you try to run this function, don't you get an error about "picture" not being a known name? (In other words, "closer, but not yet.") Mark Guzdial


def checkLuminance(r, g, b):
  newRed = int(r*.299)
  newGreen = int(g*.587)
  newBlue = int(b*.114)
  luminance = newRed + newBlue + newGreen
  if luminance< 10:
    print "That's going to be awfully dark"
  if 50< luminance <200:
    print "Looks like a good range"
  if luminance > 250:
    print "That's going to be nearly white"


Is this it?
Katie Graybeal
Very close. You can't do 50 < luminance < 200, though. See the first one for how to do it – the other two earlier ones also get this line wrong. Mark Guzdial


Here's the corrected code:
def checkLuminance(r, g, b):
  newRed = int(r*.299)
  newGreen = int(g*.587)
  newBlue = int(b*.114)
  luminance = newRed + newBlue + newGreen
  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"
However, I do have one question- we're missing the range between 10 and 50. In fact, I almost didn't think that the program didn't work because the initial RGB values I entered didn't print anything on the screen.
Rebecca

Okay, I typed "&star" to put in the asterisk, but it didn't work. I'll try this again:
def checkLuminance(r, g, b):
  newRed = int(r.299)
  newGreen = int(g.587)
  newBlue = int(b.114)
  luminance = newRed + newBlue + newGreen
  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"
Rebecca

Okay, I typed "&star" to put in the asterisk, but it didn't work. I'll try this again:
def checkLuminance(r, g, b):
  newRed = int(r*.299)
  newGreen = int(g*.587)
  newBlue = int(b*.114)
  luminance = newRed + newBlue + newGreen
  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"

Rebecca Phillips

You're right, Rebecca – some pixel values won't print anything. Flaw in the program design, not the program. Mark Guzdial





do you have to use the int command in order for JES to determine what categories the luminance values fall in? Would it work without specifying that you want an integer?

Try it! Mark Guzdial


So–anybody–is that last answer by Rebecca correct?

Every time I load this program it works, but then when I put input into it, is says something is wrong with the syntax in the last line. Any suggestions?

What are you inputting? Are you putting in something to the effect of "checkLuminance(52,32,205)" into the bottom of the screen? It works when I try it- no errors.... Hope that helps!
Rebecca Phillips

you can write the second "if" loop like so...

if 50luminance250:

makes it simpler

Jill Davis

ugh didn't show up... one more try

if 50luminance250:

ok, i don't know how to load this correctly, but its supposed to have the less than and more than signs between 50 and luminance and luminance and 250



Link to this Page