Bird
0
0

What will be printed by this code if the button connected to GPIO 20 is NOT pressed?

medium📝 Predict Output Q5 of 15
Raspberry Pi - LED and Button Projects
What will be printed by this code if the button connected to GPIO 20 is NOT pressed? import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) if GPIO.input(20) == 0: print("Pressed") else: print("Not Pressed")
APressed
BNot Pressed
CRuntime Error
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand pull-up resistor effect

    Pin reads HIGH by default; pressing button connects pin to LOW.
  2. Step 2: Evaluate condition when button not pressed

    GPIO.input(20) returns 1 (HIGH), so condition is False, prints "Not Pressed".
  3. Final Answer:

    Not Pressed -> Option B
  4. Quick Check:

    Pull-up unpressed = input HIGH = prints "Not Pressed" [OK]
Quick Trick: Pull-up means unpressed reads HIGH [OK]
Common Mistakes:
  • Assuming pressed means HIGH with pull-up
  • Confusing 0 and 1 in condition
  • Expecting error in correct code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes