help on ultra newbie program please
Andrew Walkingshaw
andrew-usenet at lexical.org.uk
Wed May 21 14:35:25 EDT 2003
In article <3ECBC0CD.AB706DBF at engcorp.com>, Peter Hansen wrote:
> Andrew Walkingshaw wrote:
>>
>> # set password to be blank initially
>> password = ""
>> # and create a variable to count the number of failed login attempts
>> numfailures = 0
>>
>> while numfailures < 3:
>> password = raw_input("Password: ")
>> if password == "unicorn":
>> # success, so get out of the loop
>> break
>> else:
>> # increment number of attempts by one
>> numfailures = numfailures + 1
>
>
> Extremely minor nit: setting password to "" in the first
> line above is useless in this case, as it will always be
> set to the user input after the call to raw_input()...
Of course; however, I don't think it does any real harm (OK, it's very
slightly memory inefficient.)
I tend to set default values for any variable I'm going to use in
serious code: I've been bitten by subtle bugs ("surely that's the first
time I've used x in this scope...") too many times not to. :)
- Andrew
--
Andrew Walkingshaw | andrew-usenet at lexical.org.uk
More information about the Python-list
mailing list