[EMAIL PROTECTED] said unto the world upon 2005-04-11 14:54:
Hey all,

Sorry for the bother, thanks for the help.

I'm trying to write a password guessing program to keep track of
how many times the user has entered the password wrong.
If it is more than 3 times, print ``That must have been complicated.''

Following is what I got. If I type "unicorn" it goes straight to "welcome in." Great. But after my third mistake, it just loops in "That must have been complicated."

I'd like for someone to tell me "why" i screwed up.  Not to just fix it.

Thank you so much in advance. And to give you a little smile for a Monday, I've been working on this for days....argh


Hi Gary,


#first of all, why does this have to be here?
password="foobar"

Given that you've structured things with a while loop that checks whether password is not equal to something else, you need to have a value for password, else you cannot check if the value of password is <whatever>. (If I asked you "Is graffleb less than 4?" you reasonably would reply "How can I answer that? You've not told me to what `graffleb' refers!")


That said, I'd use
>>> password = None
instead.


count=3
current_count=0

while password !="unicorn":
    if current_count<count:
        password=raw_input("Password:")
        current_count=current_count+1
    else:
        print "That must have been complicated"


print "Welcome in"

You'd like the loop to exit after your third mistake, right? Well, the loop hasn't been told to do that :-) The word you are looking for is `break'. If that doesn't get you to where you can make it behave as desired, post again.


HTH,

Brian vdB


_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Reply via email to