Basic question from pure beginner
wuwei23 at gmail.com
Wed Jul 1 23:56:28 EDT 2009
On Jul 2, 3:47 am, Scott David Daniels <Scott.Dani... at 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)
> # 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 :)
More information about the Python-list