The main function creates 5 pixels with random red, green, and blue values. Complete the id_color function to return “red” if the red value is greater than the green and blue, “green” if the green value is greater than the red and blue, and “blue” if the blue value is greater than the red and green. If there is no clear maximum value (
1. The main function creates 5 pixels with random red, green, and blue values. Complete the id_color function to return “red” if the red value is greater than the green and blue, “green” if the green value is greater than the red and blue, and “blue” if the blue value is greater than the red and green. If there is no clear maximum value (for example, if the red and green values are the same) return None. Do not change the main function.
import image
import random
def id_color(p):
'''Returns the dominant color of pixel p'''
pass
#Your code here to determine the dominant color and return a string identifying it
#Hint: get the red, green & blue values and use an if statement to determine which has the highest value
def main():
'''Controls the program'''
for i in range(5): #Loop 5 times
r = random.randrange(0, 256)
g = random.randrange(0, 256)
b = random.randrange(0, 256)
print(r, g, b) #Show the pixel red, green & blue values
new_pixel = image.Pixel(r, g, b)
print(id_color(new_pixel))
main() #Run the program
Trending now
This is a popular solution!
Step by step
Solved in 2 steps