Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to turn on the LED connected to GPIO pin 17.
Raspberry Pi
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.output(17, [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using False instead of True turns the LED off.
Using 0 or None does not turn the LED on.
✗ Incorrect
Setting GPIO.output to True turns the LED on.
2fill in blank
mediumComplete the code to make the LED blink once with a 1 second delay.
Raspberry Pi
import time GPIO.output(18, True) time.sleep([1]) GPIO.output(18, False)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 means no delay, LED turns off immediately.
Using 2 makes the LED stay on too long for this task.
✗ Incorrect
Using 1 second delay makes the LED stay on for 1 second before turning off.
3fill in blank
hardFix the error in the code to blink the LED 3 times with 0.5 second intervals.
Raspberry Pi
for i in range(3): GPIO.output(22, [1]) time.sleep(0.5) GPIO.output(22, False) time.sleep(0.5)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using False keeps the LED off.
Using None or 0 does not turn the LED on.
✗ Incorrect
GPIO.output needs True to turn the LED on inside the loop.
4fill in blank
hardFill both blanks to create a dictionary mapping LED pins to their on/off status for a pattern.
Raspberry Pi
led_pattern = {17: [1], 27: [2] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using None or 0 does not correctly represent on/off states.
Using False for both turns off all LEDs.
✗ Incorrect
The pattern turns on LED at pin 17 (True) and turns off LED at pin 27 (False).
5fill in blank
hardFill all three blanks to create a loop that cycles LEDs on pins 5, 6, and 13 on and off with 0.3 second delay.
Raspberry Pi
pins = [5, 6, 13] for pin in pins: GPIO.output(pin, [1]) time.sleep([2]) GPIO.output(pin, [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 second delay is too long for this pattern.
Swapping True and False reverses LED states.
✗ Incorrect
The loop turns each LED on (True), waits 0.3 seconds, then turns it off (False).