我想创建一个游戏,其中的想法是尽可能多的垃圾邮件在时间限制:9.58(它是链接到跑步)。这就是我所得到的。我的问题是,我不确定如何创建时钟,同时计算某些东西的数量/接收输入
import time
print("Spamming race")
print("*************")
print("Running and spamming have alot in common, like in in running")
print(" you want to see how quick you cross the line and in ")
print("spamming the aim is to shut down the server as quick as")
print("possible.")
max_time =1
t=31
start_time = time.time()
g=input()
distance=g.count('1')
if time.time-start_time>max_time>t:
print("And he crosses the line with a distance of ",distance)我尝试过用不同的方法来解决这个问题,但是可能有一行代码我不知道哪一行可能会有帮助。
发布于 2018-05-14 01:18:56
from datetime import timedelta,datetime
print("Spamming race")
print("*************")
print("Running and spamming have alot in common, like in in running")
print(" you want to see how quick you cross the line and in ")
print("spamming the aim is to shut down the server as quick as")
print("possible.")
td = timedelta(seconds=5)
start_time = datetime.now()
distance=0
while(start_time+td>datetime.now()):
print("check spam")
g = input()
distance +=1
print("And he crosses the line with a distance of ", distance)您可能需要考虑非阻塞输入之类的东西。
https://stackoverflow.com/questions/50318415
复制相似问题