简体   繁体   English

Python 如何制作受限计时器?

[英]Python How do I make a timer that is limited?

I am working on a soccer game and since a soccer game does for 90 minutes, I want to make it 90 seconds.我正在制作一场足球比赛,因为一场足球比赛需要 90 分钟,所以我想把它设为 90 秒。 How can my soccer game in my code end after 90 seconds?我的代码中的足球比赛如何在 90 秒后结束?

you can make function, and implement it in your code like this:你可以制作 function,并在你的代码中实现它,如下所示:

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或者您可以在 90 秒后实施实际时间安排

import datetime

endTime = datetime.datetime.now() + datetime.timedelta(seconds=90)
while True:
  if datetime.datetime.now() >= endTime:
    print('time is up') 
    break
  # Blah
  # Blah

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM