0

I want to create a game where the idea is to spam as much as possible in the time limit:9.58 (it's linked to running). Here is what I've got. My problem is I'm not sure how to create a clock whilst counting the number of something/receiving input

 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)

I have tried to approach this in different matters but it there may be a line of code I don't know which may help.

halfer
  • 18,701
  • 13
  • 79
  • 158
  • Possible duplicate of [Python 3 Timed Input](https://stackoverflow.com/questions/15528939/python-3-timed-input) – internet_user May 13 '18 at 17:01
  • If you want to display a live clock you might also want to check out [`curses`](https://docs.python.org/3/howto/curses.html), and probably some kind of threading library. – tobias_k May 13 '18 at 17:15

1 Answers1

0
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)

you might want to consider something like non-blocking input.