Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the GPIO library for Raspberry Pi.
Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using gpiozero instead of RPi.GPIO for low-level pin control.
✗ Incorrect
RPi.GPIO is the standard library to control GPIO pins on Raspberry Pi.
2fill in blank
mediumComplete the code to set GPIO pin 17 as an output.
Raspberry Pi
GPIO.setup([1], GPIO.OUT) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing input pins instead of output pins.
✗ Incorrect
Pin 17 is commonly used for relay control and must be set as output.
3fill in blank
hardFix the error in the code to turn the relay ON by setting the pin LOW.
Raspberry Pi
GPIO.output(17, [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.HIGH to turn the relay ON, which actually turns it OFF.
✗ Incorrect
For many relay modules, setting the pin LOW activates the relay (turns it ON).
4fill in blank
hardComplete the code to create a dictionary mapping relay names to their GPIO pins.
Raspberry Pi
relays = {[1]: pin for {{BLANK_3}} in ['relay1', 'relay2', 'relay3']} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect dictionary syntax or variable names.
✗ Incorrect
The dictionary starts with '{' and maps relay names to pin numbers stored in 'pin'.
5fill in blank
hardFill all three blanks to turn all relays OFF by setting their pins HIGH.
Raspberry Pi
for pin in relays.values(): GPIO.output([1], [2]) print([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.LOW to turn relays OFF, which actually turns them ON.
✗ Incorrect
We loop over each pin, set it HIGH to turn relay OFF, then print a confirmation message.