0
0
Raspberry Piprogramming~10 mins

LED class and methods in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to turn the LED on.

Raspberry Pi
led = LED(17)
led.[1]()
Drag options to blanks, or click blank then click option'
Ablink
Boff
Con
Dtoggle
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.
2fill in blank
medium

Complete 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'
Ablink
Btoggle
Coff
Don
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.
3fill in blank
hard

Fix 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'
Atoggle
Bblink
Con
Doff
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.
4fill in blank
hard

Fill 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'
Ais_lit
Bon
Coff
Dtoggle
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.
5fill in blank
hard

Fill 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'
Apin
Bis_lit
Dstate
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.