我需要能够循环这个代码的条件,如果用户想重复的程序,那么它必须循环。如果用户希望退出程序,则应显示所有超速行驶的车牌号。到目前为止,我得到的是:
import time
capturedtime=time.time()
speed_limit = 30
distance = 50
numberplates = []
newplate = ("Input number plate")
input("Press enter to start")
start_time = time.time()
input("Press enter to stop")
stop_time = time.time()
capturedtime = stop_time - start_time
print('Time taken: {:.2f} seconds'.format(capturedtime))
print('Distance: {:.2f}'.format(distance))
speed = distance / capturedtime
print('Speed: {:.2f}'.format(speed))
if speed > speed_limit:
print("You were breaking the speed limit")
numberplates.append(newplate)
如果我理解正确,您可以将所有代码放入while循环中,然后通过另一个input()停止它。在
示例:
我不太确定这是否是你要找的,但试试下面的方法。在
我刚刚在while循环中使用了你的代码。有关详细信息,请查看while循环的文档,https://wiki.python.org/moin/WhileLoop
相关问题 更多 >
编程相关推荐