Python How do I make a timer that is limited?

Question:

I am working on a soccer game and since a soccer game does for 90 minutes, I want to make it 90 seconds. How can my soccer game in my code end after 90 seconds?

Asked By: Simon Choi

||

Answers:

I’m not sure but you may be able to use and if statement saying if timer == 0 end game. that kinda thing( obviously not looking like that just am idea

Answered By: Reece Neacy

you can make function , and implement it in your code like this :

you can do it with more than way ,
here is a bunch of ways you can follow one of them :

import time 
def times_up():
    time.sleep(90)  # wait a second
    return true   # when time is up will return 

or you can implement the actual time to schedule after 90 seconds

import datetime

endTime = datetime.datetime.now() + datetime.timedelta(seconds=90)
while True:
  if datetime.datetime.now() >= endTime:
    print('time is up') 
    break
  # Blah
  # Blah
Answered By: Ahmad Akel Omar
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.