0
0
Raspberry Piprogramming~10 mins

Why LED and button projects build hardware confidence in Raspberry Pi - Test Your Understanding

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

Complete 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'
AGPIO.LOW
BGPIO.IN
CGPIO.HIGH
DGPIO.PWM
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.LOW instead of GPIO.HIGH to turn on the LED.
2fill in blank
medium

Complete the code to read the button state connected to GPIO pin 18.

Raspberry Pi
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
button_state = GPIO.input([1])
Drag options to blanks, or click blank then click option'
A18
B22
C17
D27
Attempts:
3 left
💡 Hint
Common Mistakes
Reading from the wrong GPIO pin number.
3fill in blank
hard

Fix the error in the code to toggle the LED when the button is pressed.

Raspberry Pi
if GPIO.input(18) == [1]:
    GPIO.output(17, GPIO.HIGH)
else:
    GPIO.output(17, GPIO.LOW)
Drag options to blanks, or click blank then click option'
AGPIO.HIGH
BGPIO.LOW
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for GPIO.HIGH instead of GPIO.LOW when button pressed.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Raspberry Pi
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if value is positive.

Raspberry Pi
result = { [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using k instead of k.upper() for keys.