Bird
0
0

You want to trigger an alert if an object is closer than 0.2 meters using DistanceSensor. Which code snippet correctly implements this?

hard📝 Application Q8 of 15
Raspberry Pi - gpiozero Library
You want to trigger an alert if an object is closer than 0.2 meters using DistanceSensor. Which code snippet correctly implements this?
Aif sensor.distance == 0.2: print('Alert: Object too close!')
Bif sensor.distance < 0.2: print('Alert: Object too close!')
Cif sensor.distance > 0.2: print('Alert: Object too close!')
Dif sensor.distance() < 0.2: print('Alert: Object too close!')
Step-by-Step Solution
Solution:
  1. Step 1: Use distance property correctly

    Access sensor.distance without parentheses to get current distance.
  2. Step 2: Check if distance is less than 0.2 meters

    Use < operator to detect if object is closer than 0.2 meters.
  3. Final Answer:

    if sensor.distance < 0.2: print('Alert: Object too close!') -> Option B
  4. Quick Check:

    Use property and < for proximity alert [OK]
Quick Trick: Use sensor.distance without () and compare with < [OK]
Common Mistakes:
  • Calling distance as a function
  • Using > instead of < for close detection
  • Checking equality instead of less than

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes