I'm trying to implement a 60 second timer for a boggle game, in which when the timer hits 0, the user cannot enter any more words. Right now I'm using a counter to limit the amount of words entered (which is set to twenty), I want to change this to a timer of 60 seconds, but I'm not quite sure how. Thanks in advance!
x = 20
while x > 0:
print ""
EnterWord = raw_input("Enter word here: ")
print EnterWord
x = x - 1
if x == 0:
print "20 chances have been used."
If you want a timer, use time()
:
import time
start = time.time()
while True:
if time.time() >= (start + 60):
print("Out of time")
break
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.