Implementing a timer in boggle game Python

839 views Asked by At

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."
1

There are 1 answers

4
jonrsharpe On

If you want a timer, use time():

import time

start = time.time()

while True:
    if time.time() >= (start + 60):
        print("Out of time")
        break