[Tutor] A question about None
Phil
phillor9 at gmail.com
Sun Aug 22 03:25:10 EDT 2021
The distance sensor outputs "None" if the distance is greater than can
be measured and "None", of course cannot be compared. So I came up with
the following which is not quite correct:
while True
if distance_sensor.get_distance_cm() is not None:
if distance_sensor.get_distance_cm() > 20:
motor_pair.set_default_speed(20)
motor_pair.start()
else:
continue
elif distance_sensor.get_distance_cm() is not None:
if distance_sensor.get_distance_cm() < 20:
motor_pair.set_default_speed(-20)
motor_pair.start()
else:
continue
The idea is that if "None" returned from the sensor then nothing will
happen and the loop will continue until "None" is not returned. Can
anyone see the error of my ways?
--
Regards,
Phil
More information about the Tutor
mailing list