Answer :
Question 2 Edhesive: Write a program to check for valid RGB values
Answer:
In Python:
r = int(input("Red: "))
g = int(input("Green: "))
b = int(input("Blue: "))
if not(r>=0 and r <= 255):
print("Invalid Red Code")
if not(g>=0 and g <= 255):
print("Invalid Green Code")
if not(b>=0 and b <= 255):
print("Invalid Blue Code")
Explanation:
The next three lines prompt the user for red, green and blue color codes
r = int(input("Red: "))
g = int(input("Green: "))
b = int(input("Blue: "))
This checks if the red color code is between 0 and 255 (inclusive). If no, an invalid message is printed
if not(r>=0 and r <= 255):
print("Invalid Red Code")
This checks if the green color code is between 0 and 255 (inclusive). If no, an invalid message is printed
if not(g>=0 and g <= 255):
print("Invalid Green Code")
This checks if the blue color code is between 0 and 255 (inclusive). If no, an invalid message is printed
if not(b>=0 and b <= 255):
print("Invalid Blue Code")