Complete the code to set up a GPIO pin as an output on a Raspberry Pi.
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup([1], GPIO.OUT)
The number 17 refers to the GPIO pin number in BCM mode. This sets pin 17 as an output.
Complete the code to turn on an LED connected to GPIO pin 18.
GPIO.output([1], GPIO.HIGH)Pin 18 is the GPIO pin connected to the LED. Setting it HIGH turns the LED on.
Fix the error in the code to read the state of a button connected to GPIO pin 23.
button_state = GPIO.input([1])
GPIO.input requires the pin number to read its state. Pin 23 is correct here.
Fill both blanks to create a dictionary mapping USB port numbers to their status.
usb_status = [1]((port, 'connected' if port [2] [1, 2] else 'disconnected') for port in range(1, 5))
We use dict() to create a dictionary. The 'in' keyword checks if the port is in the list [1, 2].
Fill all three blanks to create a dictionary of HDMI ports with their resolutions if active.
hdmi_info = [1]: [2] if status [3] 'active' else 'inactive' for [1], status in [('HDMI1', 'active'), ('HDMI2', 'inactive')]}}
We use 'port' as the key. If status is 'active' (checked with '=='), we assign resolution '1920x1080'.