重新启动自己的程序?
问题描述:
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.")
我想在使用它之后重新启动程序,以便我可以检查车辆的速度不止一次。重新启动自己的程序?
请帮我完成代码,以便我可以自行重新启动代码并检查多个车辆的速度。
答
使用while
循环。
while True:
# Do your code
底:
again = input("Do this again?")
again = again.lower()
if again.startswith('n'):
break # Get out of the loop
+0
它说中断在循环之外 – 2015-03-24 21:16:28
+0
你把整个东西放到循环中吗? – Zizouz212 2015-03-24 21:17:12
+0
它说打破外环 – 2015-03-24 21:18:09
帮助我的代码,可以帮助的代码中本身重启像连续循环 – 2015-03-24 21:07:16
为什么你不只是用'while'循环? – Makoto 2015-03-24 21:07:39
*“给我代码”* - 不,请自己完成GCSE课程。 – jonrsharpe 2015-03-24 21:07:47