Best way to do this?

Jeff Epler jepler at
Sun Jan 18 00:26:26 CET 2004

def getpass(password, count=3):
	for i in range(count):
		p = raw_input("Password: ")
		if p == password: return 1
	return 0

No need to initialize count to 0 and use a while loop, use a "for" loop
instead.  No need to initialize password above the loop (and if you had
to, use None instead of "null"), and no need to set count to 3 when the
correct password is entered---just use return or break.


More information about the Python-list mailing list