Exercise #3 o Write a program averageLuminance(picture) which takes as input a picture uses functional programming to calculate the average luminance of the picture’s pixels. Use the helper function def luminance(pixel): r = getRed(pixel) g = getGreen(pixel) b = getBlue(pixxel) y = 0.2126 * r + 0.7152 * g + 0.0722 * b return y Within your main program, use map and luminance to create a list of luminances from the list of pixels. This is an example answer to help you formulate an answer for the question above: # Exercise 3 def isDocument(fileName): listOfEndings = [ ".docx", ".txt", ".rtf" ] for ending in listOfEndings: if fileName.endswith(ending): return True return False def recursiveListDocuments(directory=os.getcwd()): files = os.listdir(os.path.normpath(directory)) for file in files: fileName = os.path.normpath(directory + "/" + file) if isDirectory(fileName): recursiveListDocuments(fileName) else: if isDocument(fileName): print fileName
Exercise #3
o Write a program averageLuminance(picture) which takes as input a picture uses functional
Use the helper function
def luminance(pixel):
r = getRed(pixel)
g = getGreen(pixel)
b = getBlue(pixxel)
y = 0.2126 * r + 0.7152 * g + 0.0722 * b
return y
Within your main program, use map and luminance to create a list of luminances from the list of pixels.
This is an example answer to help you formulate an answer for the question above:
# Exercise 3 def isDocument(fileName): listOfEndings = [ ".docx", ".txt", ".rtf" ] for ending in listOfEndings: if fileName.endswith(ending): return True return False def recursiveListDocuments(directory=os.getcwd()): files = os.listdir(os.path.normpath(directory)) for file in files: fileName = os.path.normpath(directory + "/" + file) if isDirectory(fileName): recursiveListDocuments(fileName) else: if isDocument(fileName): print fileName
Trending now
This is a popular solution!
Step by step
Solved in 2 steps