Ask the user to enter a number for red, green, and blue components of an RGB value. Test to make sure each value is between 0 and 255 inclusive. If a color's value is out of range, print which component is not correct (e.g., "Red number is not correct" if the red value is 300). Multiple colors may be out of range.

Respuesta :

Answer:

  1. r = int(input("Enter a number for red channel: "))
  2. g = int(input("Enter a number for green channel: "))
  3. b = int(input("Enter a number for blue channel: "))  
  4. if(r < 0 or r >255):
  5.    print("Red number is not correct.")
  6. if(g < 0 or g >255):
  7.    print("Green number is not correct.")
  8. if(b < 0 or b >255):
  9.    print("Blue number is not correct.")

Explanation:

The solution code is written in Python.

Firstly, prompt user to input three numbers for red, green and blue (Line 1-3).

Next, create three similar if statements to check if the red, green and blue are within the range 0-255 by using logical operator "or" to check if the number is smaller than 0 or bigger than 255. If either one condition is met, display a message to indicate a particular color number is not correct (Line 5-12).

fichoh

The program written in python 3 which displays the whether the range of RGB values inputted by the user is in range goes thus :

r = int(input('Enter red value between 0 - 255'))

g = int(input('Enter green value between 0 - 255'))

b = int(input('Enter blue value between 0 - 255'))

#accepts inputs for red, green and blue values from the user

vals = {'red':r, 'green':g, 'blue':b}

#read the values into a dictionary and assign the values inputted by the user as the values

for k, v in vals.items():

#iterate through the dictionary as key-value pairs

if(v < 0) or (v > 255):

#Check of the values inputted is within range (0 - 255)

print('%s is not correct' %k)

#for any value which is out of range, display the name of the color and state that it is incorrect.

A sample run of the program ls attached below.

Learn more :https://brainly.com/question/18802298

Ver imagen fichoh