Basic question from pure beginner

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Wed Jul 1 18:45:26 CEST 2009


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.



More information about the Python-list mailing list