Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

def get invalid_colors(list): There are many ways to represent colors in a compu

ID: 3721983 • Letter: D

Question

def get invalid_colors(list): There are many ways to represent colors in a computer, but one common is to specify the intensity of three colored lights: red, green, and blue. By combining these lights, computers can produce more interesting colors (for example, red and green together make yellow). Computers typically represent the intensity of the lights as values between O and 255 (inclusive) This function accepts a list of tuples where each tuple represents a color with three values: one for the intensity of red, one for the intensity of green, and one for the intensity of blue. The function then returns t indices of any invalid colors in the list. he indices of invalid colors Return value: a (possibly empty) list of integers which indicate t . Assumptions: o list will be a (possibly empty) list of tuples, each tuple will have three integer values Notes Hint: You may want to make a "helper function" for this... Curious why 255? You may remember from your readings that computers store numbers in binary. 255 is the largest binary number that can be stored in 8 bits (I byte): 1111 1111. o o .Examples: # The method call below is given two colors: (8,8,8) and (-1,,255) # the second color (index 1) has an invalid value for red (-1) get invalid_colors(I(e,0,0), (-1,0,255)1) # The method call below is given two colors: (8,277,0) and (-1,e,500) # the first color (index ) has an invalid value for green (277) # the second color (index 1) has an invalid value for red (-1) and blue (see) get invalid_colors(I(0,277,0),(-1,0,500)1) o # The method call below is given three colors: (3,1,0), (0,53,255), and (0,0,0) # all are valid so an empty list is returned get_invalid-colors([(30,1,0),(8,53,255),(0,0,0))) []

Explanation / Answer

def get_invalid_colors(l):
colors=[] #store the indices of invalid colors in the list
for i in range(len(l)):
(r,g,b)=l[i] #extract red,green and blue values
if r<0 or r>255 or g<0 or g>255 or b<0 or b>255:
colors.append(i)
return colors