Complete the code to turn on the LED connected to GPIO pin 17.
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.output(17, [1])
GPIO.HIGH sets the pin to high voltage, turning the LED on.
Complete the code to read the button state connected to GPIO pin 18.
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) button_state = GPIO.input([1])
The button is connected to GPIO pin 18, so we read from pin 18.
Fix the error in the code to toggle the LED when the button is pressed.
if GPIO.input(18) == [1]: GPIO.output(17, GPIO.HIGH) else: GPIO.output(17, GPIO.LOW)
The button uses a pull-up resistor, so pressed means GPIO.LOW.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
lengths = {word: [1] for word in words if len(word) [2] 3}We map each word to its length using len(word) and filter words longer than 3 with > 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if value is positive.
result = { [1]: [2] for k, v in data.items() if v [3] 0}We convert keys to uppercase with k.upper(), keep values as v, and filter values > 0.