在自己内部重新启动程序?

时间:2015-03-24 21:06:28

标签: python python-2.7 python-3.x

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.")

我想在使用它后重新启动程序,以便我可以多次检查车辆的速度。

请帮我完成代码,以便我可以自行重启代码并检查多辆车的速度。

1 个答案:

答案 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