Hi! Slightly different (extented) than your original question, but here's how I'd do this (although the program doesn't really do very much):
import time, random def is_valid_date(): while True: prompt = 'Enter the date in ISO format (YYYY-MM-DD), or 0 to exit: ' date = raw_input(prompt) try: time.strptime(date, "%Y-%m-%d") print "You've entered: %s" % date return True except ValueError: if date == str(0): print "Finished!" break else: print "Invalid date or invalid date format (%s)" % date return False def do_something(): for i in range(10): print "%05d" % random.randint(0, 10**4) if is_valid_date(): do_something() Cheers!! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In the face of ambiguity, refuse the temptation to guess. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- On Fri, 11/20/09, Ken G. <beach...@insightbb.com> wrote: From: Ken G. <beach...@insightbb.com> Subject: [Tutor] Breaking out of loop... To: tutor@python.org Date: Friday, November 20, 2009, 6:02 PM I am trying to break out of a loop posted below. When asked for monthdate, it should break out if I entered the number zero and it does not. GRRR. Been working on this for almost an hour. monthdate = 999 while monthdate <> 0: monthdate = raw_input('Enter the month and date in two digit format each: ') month = monthdate[0:2] date = monthdate[2:4] year = ('2009') print month, date, year print "Finished!" Thanking you all in advance for your help. Ken _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor