0

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."
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
YashMorar
  • 7
  • 3

1 Answers1

2

If you want a timer, use time():

import time

start = time.time()

while True:
    if time.time() >= (start + 60):
        print("Out of time")
        break
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • I've added this, but it doesn't print "time is up!" if time.time() == 0? – YashMorar Jan 25 '14 at 14:30
  • `time.time()` is the *current time*, it will never be 0. Test for `time.time() >= (start + 60)` – jonrsharpe Jan 25 '14 at 14:33
  • Hm, still not working, the program just continues even if the condition is no longer met? Could it be that time.time() is constantly updating to the present time and so it continues in an infinite loop? Cause the Python Shell is constantly running and comes up with the message "The program is still running! Are you sure you want to quit?" – YashMorar Jan 25 '14 at 14:49
  • Try `while True: if time.time() > start + 60: break` – jonrsharpe Jan 25 '14 at 15:01