David wrote:
Norman Khine wrote:
On Mon, Apr 27, 2009 at 12:07 AM, Sander Sweers <sander.swe...@gmail.com> wrote:
Here is another one for fun, you run it like
python countdown.py 10

#!/usr/bin/env python

import sys
from time import sleep

times = int(sys.argv[1]) # The argument given on the command line

def countdown(n):
    try:
        while n != 1:
            n = n-1
            print n
            sleep(1)
    finally:
        print 'Blast Off!'

countdown(times)

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Thank you all for all your valuable input on this. I have learned so much on this particular subject in such a short time. David, I ran your code, and noticed that given countdown(10) your countdown
starts at 9 and Blastoff takes place after 1, not 0. To fix that, I changed

      while n ! = 1

to
while n != 0


and changed

      n = n - 1
      print n

to

      print n
      n = n -1


Thanks for the time you guys have put into this. It's much appreciated. :-)

Dayo
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to