Bird
0
0

Which of the following Python code snippets correctly sets up GPIO pin 18 as an output for an LED in a reaction time game?

easy📝 Syntax Q3 of 15
Raspberry Pi - LED and Button Projects
Which of the following Python code snippets correctly sets up GPIO pin 18 as an output for an LED in a reaction time game?
AGPIO.output(18, GPIO.IN)
BGPIO.setup(18, GPIO.OUT)
CGPIO.setup(18, GPIO.IN)
DGPIO.input(18, GPIO.OUT)
Step-by-Step Solution
Solution:
  1. Step 1: Recall GPIO setup syntax

    To set a pin as output, use GPIO.setup(pin_number, GPIO.OUT).
  2. Step 2: Check each option

    GPIO.setup(18, GPIO.OUT) correctly sets pin 18 as output. GPIO.setup(18, GPIO.IN) sets it as input, which is wrong for LED. Options A and D misuse GPIO.output and GPIO.input functions.
  3. Final Answer:

    GPIO.setup(18, GPIO.OUT) -> Option B
  4. Quick Check:

    GPIO output setup = GPIO.setup(pin, GPIO.OUT) [OK]
Quick Trick: Use GPIO.setup(pin, GPIO.OUT) to set output pins [OK]
Common Mistakes:
  • Using GPIO.IN for output pins
  • Calling GPIO.output() instead of GPIO.setup() to configure pins
  • Mixing GPIO.input() and GPIO.output() functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes