Bird
0
0

How can you continuously monitor distance and print a warning only when the distance changes significantly (more than 0.1 meters) from the last reading?

hard📝 Application Q9 of 15
Raspberry Pi - gpiozero Library
How can you continuously monitor distance and print a warning only when the distance changes significantly (more than 0.1 meters) from the last reading?
AUse a loop storing last distance and compare with current distance each iteration
BCall sensor.distance() repeatedly without storing previous value
CUse sensor.distance property once outside the loop
DPrint warning every time without checking distance change
Step-by-Step Solution
Solution:
  1. Step 1: Store last distance value

    Keep a variable to remember the previous distance reading.
  2. Step 2: Compare current distance with last distance in a loop

    Print warning only if difference is greater than 0.1 meters.
  3. Final Answer:

    Use a loop storing last distance and compare with current distance each iteration -> Option A
  4. Quick Check:

    Track changes by comparing current and last distance [OK]
Quick Trick: Store last reading to detect significant changes [OK]
Common Mistakes:
  • Not storing previous distance
  • Calling distance as a function
  • Printing warning unconditionally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes