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

Spring 2006 Midterm 1 Review: Check your luminance

Spring 2006 Midterm 1 Review: Check your luminance here.


This one works
def checkLuminance(r, g, b):
  luminance=r*.3+g*.59+b*.11
  print r*.3+g*.59+b*.11
  if(luminance<10):
    return "That's going to be awfully dark"
  if(luminance>=10 and luminance<=50):
    return "A little dark"
  if(luminance>50 and luminance<200):
    return "Looks like a good range"
  if(luminance>=200 and luminance<250):
    return "Getting kinda bright"
  if(luminance>=250):
    return "AHHH! MY EYES"

Paul

For this part, it says "Greater than or equal to 10 OR less than or equal to 50," would you write it as

if luminance >=10 or luminance <=50, or if luminance >=10 and luminance =50?
you'd use an "and". Make sure you know how to write > and < signs on the coweb, or use code tags to put your answer in...Amanda Bennett

shoudln't the first line be def checkLuminance(r, g, b): ?

i mean def checkLuminance(picture, r, g, b):

i think that it's not (picture, r, g, b): because it says that it's suppose to take in 3 numbers representing red, green and blue values, i don't think the picture is involved in it.

That's right. There's no picture in sight. Colin Potts

Could you use print instead of return in this situation?

Strictly speaking, given the wording of the question, you SHOULD use a print in this situation instead of a return, since the question says that the function should print a message. If that's what the customer wants.... But it would be better in general to return the string as Paul suggests and have the calling function do the printing. After all, maybe we need to do something to the string before printing it, like put a tab at the beginning, turn it into upper case, concatenate the string ", Houston." on the end. Do that in the calling function, and you only have one change to make. Do it in checkLuminance and you have several changes that to make that are about formatting strings, not checking luminance. Colin Potts

If a question like this appears on the test, will we be given the weighted averages like we are here? Or do we need to remember them?
You do not have to remember weighted averages -Albert d'Heurle



Link to this Page