In: Computer Science
Python: Write the function pixelLuminance that takes 3 integers r, g, and b, each between 0 and 255 (inclusive), representing the red, green, and blue intensity of a pixel and returns the luminance of this pixel as an integer. The function expects each parameter r, g, and b to be an integer in the interval [0,255]. You should use assertions to enforce this constraint.
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! =========================================================================== # formula => luminance = (r * 0.3) + (g * 0.59) + (b * 0.11) def pixelLuminance (r,g,b): assert 0<=r and r<=255 assert 0<=g and g<=255 assert 0<=b and b<=255 return (r * 0.3) + (g * 0.59) + (b * 0.11) print(pixelLuminance(0,0,0)) print(pixelLuminance(255,255,255)) print(pixelLuminance(128,128,128)) try: print(pixelLuminance(255,80,1000)) except AssertionError: print('Invalid input')