Bird
0
0

Which of the following is the correct way to import the GPIO library and set pin 18 as output in Python for Raspberry Pi?

easy📝 Syntax Q12 of 15
Raspberry Pi - LED and Button Projects
Which of the following is the correct way to import the GPIO library and set pin 18 as output in Python for Raspberry Pi?
Aimport RPi.GPIO as GPIO\nGPIO.setup(18, GPIO.OUT)
Bimport RPi.GPIO as GPIO\nGPIO.setup(18, GPIO.IN)
Cimport gpiozero\nGPIO.setup(18, GPIO.OUT)
Dimport RPi.GPIO as GPIO\nGPIO.output(18, GPIO.OUT)
Step-by-Step Solution
Solution:
  1. Step 1: Import the correct library

    Use import RPi.GPIO as GPIO to access GPIO functions.
  2. Step 2: Set pin 18 as output

    Use GPIO.setup(18, GPIO.OUT) to configure pin 18 for output.
  3. Final Answer:

    import RPi.GPIO as GPIO\nGPIO.setup(18, GPIO.OUT) -> Option A
  4. Quick Check:

    GPIO setup output = correct syntax [OK]
Quick Trick: Use GPIO.setup(pin, GPIO.OUT) to set output pin [OK]
Common Mistakes:
  • Using GPIO.IN instead of GPIO.OUT
  • Calling GPIO.output instead of GPIO.setup for pin mode
  • Importing wrong library like gpiozero

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes