from datetime import datetime
platenumber = input("Enter the license plate number:")
start = input("Press enter to start.")
starttime =(datetime.now())
stop = input("Press enter to stop.")
stoptime =(datetime.now())
dist1 = 0
dist2 = input("Enter the distance of the road in metres:")
time = ((stoptime - starttime).total_seconds())
print((time),"is the time in seconds.")
distance = int(dist2) - dist1
print((distance),"is the the distance in metres.")
speed = float(distance)//time
print((speed),"is the speed of the vehicle in m/s.")
我想在使用它后重新启动程序,以便我可以多次检查车辆的速度。
请帮我完成代码,以便我可以自行重启代码并检查多辆车的速度。
答案 0 :(得分:1)
使用while
循环。
while True:
# Do your code
最后:
again = input("Do this again?")
again = again.lower()
if again.startswith('n'):
break # Get out of the loop