New More Exciting Logic for Ultrasonic

Here is the code
#! /usr/bin/python
#import RPi.GPIO as GPIO
import time
from random import sample

def checkdist():
        time.sleep(0.000015)
        t1 = time.time()
        time.sleep(2)
        t2 = time.time()
        return (t2-t1)*340/2

def fakedist():
        list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        return sample(list1,1)[0]

time.sleep(1)

gled="off"
yled="off"
rled="off"
print(gled, yled, rled)
try:
        while True:
                print('Distance: %0.2f m' %checkdist())
                dist = fakedist()
                print('fake: %0.2f m' %dist)
                if dist > 7:
                        gled="on"
                        yled="off"
                        rled="off"
                if dist > 2 and dist < 8:
                        gled="off"
                        yled="on"
                        rled="off"
                if dist < 3:
                        gled="off"
                        yled="off"
                        rled="on"


                print(gled, yled, rled)

                time.sleep(0.5)
except KeyboardInterrupt:
        pass

Blink some LEDs

#https://roboticsbackend.com/raspberry-pi-control-led-python-3/
#https://lowvoltagelabs.com/products/pi-traffic/
#https://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/
import RPi.GPIO as GPIO
import time
LED_G = 16 
LED_R = 20
LED_Y = 21 
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_R, GPIO.OUT)
GPIO.setup(LED_G, GPIO.OUT)
GPIO.setup(LED_Y, GPIO.OUT)
#
GPIO.output(LED_G, GPIO.HIGH)
time.sleep(1)
GPIO.output(LED_Y, GPIO.HIGH)
time.sleep(1)

GPIO.output(LED_R, GPIO.HIGH)

time.sleep(1)
GPIO.output(LED_R, GPIO.LOW)
time.sleep(1)

GPIO.output(LED_Y, GPIO.LOW)
time.sleep(1)

GPIO.output(LED_G, GPIO.LOW)

GPIO.cleanup()