Consider this Python code controlling an RGB LED on a Raspberry Pi. What color will the LED show?
red = 255 green = 100 blue = 0 if red > green and red > blue: color = 'Red' elif green > red and green > blue: color = 'Green' else: color = 'Blue' print(color)
Check which color value is the highest number.
The red value (255) is greater than green (100) and blue (0), so the output is 'Red'.
This code mixes RGB values to create a color. What is the printed output?
def mix_color(r, g, b): return f'#{r:02X}{g:02X}{b:02X}' color_code = mix_color(0, 128, 128) print(color_code)
Look at the hexadecimal format for green and blue values.
The green and blue values are both 128 decimal, which is 80 in hex, so the combined hex color is '#008080'.
Find the error in this Raspberry Pi RGB LED control code and identify the error type.
red = 255 green = 255 blue = 255 color = {red, green, blue} print(color)
Look at the curly braces and what they create in Python.
Curly braces with comma-separated values create a set {255, 255, 255}, so the code prints the set.
This code adjusts brightness of an RGB LED using PWM values. What is printed?
brightness = 0.5 red = int(255 * brightness) green = int(100 * brightness) blue = int(50 * brightness) print(red, green, blue)
Remember int() truncates decimals down.
255*0.5=127.5 truncated to 127, 100*0.5=50, 50*0.5=25, so output is '127 50 25'.
When mixing colors with RGB LEDs, which statement is true?
Think about how light colors combine, not paint.
In additive color mixing, red plus green light makes yellow light.