473,323 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Countdown from 2 minutes - how?

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.

Henrik

Mar 30 '06 #1
4 3502
he****@wollesens.dk wrote:
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"


here's a first version:

import time
time.sleep(2*60)
print "Time is up"

to improve this, I suggest reading the chapter on loops in the tutorial:

http://docs.python.org/tut/node6.html

</F>

Mar 30 '06 #2

he****@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


Mar 30 '06 #3
#!/bin/env python
# countdown.py
import time
import doctest

def countdown( time_in_minutes):
"""
import countdown
countdown.countdown(0.1) # doctest:+ELLIPSIS

6
5
...
1
Time is up
"""
for i in reversed(xrange(1, int(time_in_minutes * 60) + 1)):
print i
time.sleep(1)
print 'Time is up'

if __name__=='__main__':
doctest.testmod()

Mar 30 '06 #4
#!/bin/env python
# countdown.py

import time
import doctest

def countdown( time_in_minutes):
"""
import countdown
countdown.countdown(0.1) # doctest:+ELLIPSIS

6
5
...
1
Time is up
"""
for i in xrange(int(time_in_minutes * 60 + 0.5), 0, -1):
print i
time.sleep(1)
print 'Time is up'

if __name__=='__main__':
doctest.testmod()

Mar 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matt Stanley | last post by:
I am using the countdown script developed by Chris Nott on his website(http://www.dithered.com/javascript/countdown/example.html). The script counts down the days, hours, minutes and seconds to a...
3
by: Bonnett | last post by:
I have been creating a generic countdown timer (source code below), counting the seconds, minutes, hours and days till an event, but I have having trouble with it finding out how many hours are...
4
by: Christine | last post by:
I've implemented a countdown timer for a tutorial web page that should give the user 45 minutes to complete the test, only to find that the timer is slowly 'losing' time. On average, it actually...
8
by: Michael | last post by:
I have this script that works the way I want except for one thing... Once it hits zero it starts to count up and looks like this: -1:0-1:0-1:0-18 with the last number counting up. Can anyone...
3
by: Sheep Shagger | last post by:
Hello all This is driving me crazy. I am trying to write a small program that when started counts down from 16:30 heres what I mean:- say I launch the programme at 10:00 then i've like to...
1
by: Dirk Hagemann | last post by:
Hi! I'd like to implement a countdown timer on a webite. It should show the months, days, hours, minutes and seconds until a given date and time. So far it's not really difficult, but this...
9
by: Yet Another One | last post by:
Sorry if this has been answered before, but I simply cannot find the solution on my own. I am looking to do a countdown in my application. Basically, I need to count down from 5:59 (5 minutes,...
9
by: MC | last post by:
I would like to display a timer in the corner of the page that shows the user how many minutes:seconds till the session times out. Are there any good examples out there? Google has again failed...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.