Countdown from 2 minutes - how?
Fuzzyman
fuzzyman at gmail.com
Thu Mar 30 08:56:53 EST 2006
henrik at wollesens.dk wrote:
> Hi.
>
> Can anyone tell me the python code for a simple countdown from eg. 2.00
> minutes.
>
> It should be printet out to the screen.
> When it is finished it should write "Time is up"
>
> Hope you can help.
>
You need the module ``time`` :
import time
start = time.time()
lastprinted = 0
finish = start + 120
while time.time() < finish:
now = int(time.time())
if now != lastprinted:
print int(finish - now)
lastprinted = now
time.sleep(0.5) # this stops the system hanging whilst this is
running
print "Time is up"
HTH
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
> Henrik
More information about the Python-list
mailing list