Complete the code to import the DistanceSensor class from gpiozero.
from gpiozero import [1]
The DistanceSensor class is imported from the gpiozero library to use the ultrasonic sensor.
Complete the code to create a DistanceSensor object with trigger pin 17 and echo pin 18.
sensor = DistanceSensor(trigger=[1], echo=18)
The trigger pin is set to GPIO 17 as specified.
Fix the error in the code to print the distance in centimeters.
print(f"Distance: {sensor.[1] * 100:.1f} cm")
The distance property returns the distance in meters. Multiplying by 100 converts it to centimeters.
Fill both blanks to create a dictionary of distances for sensors on pins 5 and 6, only if distance is less than 0.5 meters.
distances = {pin: sensor.distance for pin in [5, 6] if sensor.distance [1] [2]The condition checks if the distance is less than 0.5 meters.
Fill all three blanks to create a dictionary with pin numbers as keys, distances in cm as values, only for distances greater than 0.2 meters.
dist_cm = {pin: sensor.[1] * 100 for pin in [7, 8] if sensor.[2] > [3]The dictionary comprehension converts distance to centimeters and filters distances greater than 0.2 meters.