Bird
0
0

What will the following code print if the sensor measures 0.25 meters?

medium📝 Predict Output Q13 of 15
Raspberry Pi - gpiozero Library
What will the following code print if the sensor measures 0.25 meters?
from gpiozero import DistanceSensor
sensor = DistanceSensor(echo=17, trigger=4)
distance_cm = sensor.distance * 100
print(round(distance_cm))
A25
B0.25
C250
D2.5
Step-by-Step Solution
Solution:
  1. Step 1: Understand sensor.distance value

    The sensor.distance returns distance in meters as a float, here 0.25 meters.
  2. Step 2: Convert meters to centimeters and round

    Multiplying 0.25 by 100 gives 25 centimeters, then rounding keeps it 25.
  3. Final Answer:

    25 -> Option A
  4. Quick Check:

    0.25 m * 100 = 25 cm [OK]
Quick Trick: Multiply meters by 100 to get centimeters [OK]
Common Mistakes:
  • Printing meters instead of centimeters
  • Multiplying by 1000 instead of 100
  • Not rounding the result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes