On Jul 2, 3:47 am, Scott David Daniels <scott.dani...@acm.org> wrote: > And even simpler: > PASSWORD = "qwerty" > MAXRETRY = 3 > for attempt in range(MAXRETRY): > if raw_input('Enter your password: ') == PASSWORD: > print 'Password confirmed' > break # this exits the for loop > print 'Access denied: attempt %s of %s' % (attempt+1, MAXRETRY) > else: > # The else for a for statement is not executed for breaks, > # So indicates the end of testing without a match > raise SystemExit # Or whatever you'd rather do.
Nice one, I always forget about for-else :) -- http://mail.python.org/mailman/listinfo/python-list