[Tutor] Cell Bio Newbie Here
python at jayloden.com
Mon Apr 11 21:45:45 CEST 2005
Ok, it's a logic error in the while loop. Starting at the beginning: you
can't compare the value of "password" until the user inputs the value, which
is why it's requiring you to put password = "foobar" at the top. Otherwise,
password has no value, and as far as the interpreter is concerned, it doesn't
The rest of it is a logic error because your while loop is executing as long
as "unicorn" != "foobar" and therefore it's continuously looping. Each time
it loops, it asks for the password again, and sets a LOCAL variable called
password to the new raw_input. Then, when you get to the third time, it does
the "if current_count<count:", realizes it doesn't match, and skips the rest
of the if statement, moving to the else. When it gets to the else, it prints
out your error messge, then loops all over again.
You have to provide it a way to break out of the loop and correctly compare
the value of the user input to "unicorn"
You'd be better off with something more like
while raw_input("Password: ") != "unicorn:
or maybe reworking the whole thing to work in a for loop, since I'm assuming
you only want it to give them three chances? Generally, if you know how many
times you want something to happen, it's best to use a for loop rather than a
On Monday 11 April 2005 07:54 pm, glaevsky at ECE.NEU.EDU wrote:
> 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.
> #first of all, why does this have to be here?
> while password !="unicorn":
> if current_count<count:
> print "That must have been complicated"
> print "Welcome in"
> Gary Laevsky, Ph.D.
> Keck Facility Manager, CenSSIS
> Northeastern University
> 302 Stearns
> 360 Huntington Ave.
> Boston, MA 02115
> voice(617) 373 - 2589<br>
> fax(617) 373 - 7783<br><br>
> Tutor maillist - Tutor at python.org
More information about the Tutor