Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to turn the LED on.
Raspberry Pi
led = LED(17) led.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'off' instead of 'on' will turn the LED off.
Using 'blink' or 'toggle' will not simply turn the LED on.
✗ Incorrect
The on() method turns the LED on.
2fill in blank
mediumComplete the code to make the LED blink once.
Raspberry Pi
led = LED(18) led.[1](1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'on' will keep the LED on without blinking.
Using 'off' will turn the LED off.
Using 'toggle' switches the LED state but does not blink.
✗ Incorrect
The blink() method makes the LED blink. The argument 1 means blink once.
3fill in blank
hardFix the error in the code to toggle the LED state.
Raspberry Pi
led = LED(22) led.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'blink' will make the LED flash instead of toggling.
Using 'on' or 'off' sets the LED to a fixed state.
✗ Incorrect
The toggle() method changes the LED from on to off or off to on.
4fill in blank
hardFill both blanks to create a dictionary with LED pins and the results of LED methods on those pins.
Raspberry Pi
led_states = {17: LED(17).[1](), 18: LED(18).[2]()} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'on' instead of 'is_lit' will turn the LED on instead of checking.
Using 'toggle' will change the LED state instead of turning it off.
✗ Incorrect
The is_lit() method checks if the LED is on, and off() turns the LED off.
5fill in blank
hardFill all three blanks to create a dictionary comprehension with LED pin names and states.
Raspberry Pi
led_status = {{ [1]: LED([3]).[2]() for [3] in [17, 18, 22] }} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for key and loop variable causes errors.
Using 'on' or 'off' instead of 'is_lit' changes LED state instead of checking.
✗ Incorrect
The dictionary uses the pin number as key (pin), calls is_lit() to get the LED state, and loops over pins using pin.