Bird
0
0

Find the bug in this snippet:

medium📝 Debug Q7 of 15
Raspberry Pi - gpiozero Library
Find the bug in this snippet:
from gpiozero import Button
button = Button(3)
if button.is_pressed:
    print("Pressed")
else:
    print("Not pressed")
AButton pin 3 is reserved and cannot be used
Bis_pressed should be called as a method with ()
CNo bug; code works as expected
DMissing parentheses in print statements
Step-by-Step Solution
Solution:
  1. Step 1: Check is_pressed usage

    is_pressed is a property, accessed without parentheses.
  2. Step 2: Verify other parts

    Pin 3 is valid, print syntax is correct for Python 3.
  3. Final Answer:

    No bug; code works as expected -> Option C
  4. Quick Check:

    is_pressed property usage = A [OK]
Quick Trick: is_pressed is a property, no () needed [OK]
Common Mistakes:
  • Calling is_pressed as a method
  • Assuming pin 3 is invalid
  • Confusing print syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes