[Tutor] Timing a loop: How to interrupt ?

Sheila King sheila@thinkspot.net
Sun, 13 May 2001 21:37:04 -0700


I'm writing a portion of a Boggle game for my students who are learning Python
right now. I'm going to let them extend it and finish it up. Right now, it just
rolls up the 16 dice and places them randomly in the tray, displays the tray and
lets you type in words that you see, until the time is over two minutes.

[There is currently no dictionary checking, no scoring, etc... I'm leaving that
for the students.]

I've included my script below.

The problem is this:

When the board is initialized, and just before it is displayed, the timer
starts. Then the board is displayed. I have a while loop, that checks whether
the time is over two minutes. If it is not, it asks for the player to enter a
word. After a word is entered, the time is checked. If time is still under two
minutes, it enters the loop again, and waits for the user to input a word.

The problem is, if the time is at 1:58 and goes into the loop, the player may
not enter another word until quite a bit after two minutes is up. So the game
doesn't strictly enforce the two minute limit.

Is there an easy way for me to check for the time, without letting the game go
over two minutes?

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/