Scott David Daniels a écrit : (snip)
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.
Which is probably the most pythonic implementation. -- http://mail.python.org/mailman/listinfo/python-list