Hi Gary, <br>
<br>
In a while loop, you could looping until the while condition is no longer true.<br>
So your one - <br>
<br>
<br>
while password != "unicorn"<br>
<br>
So while password isn't unicorn, your condition is True, so your while
loop will keep looping until the password equals 'unicorn'<br>
<br>
After your 3rd mistake, the if current_count<count condition is no
longer True, so you can't change the password, so the while loop will
go infinite. <br>
<br>
Python goes <br>
<br>
Is password unicorn? Nope.<br>
Is current_count < count? Nope.<br>
better print "That must have been complicated"<br>
Is password unicorn? Nope.<br>
Is current_count < count? Nope.<br>
better print"That must have been complicated"<br>
Is password unicorn? Nope.<br>
Is current_count < count? Nope.<br>
better print "That must have been complicated"<br>
<br>
if you get the drift. <br>
<br>
If you want it to be<br>
<br>
Is password unicorn? Nope.<br>
Is current_count < count? Yup.<br>
Get password....<br>
Is password unicorn? Nope.<br>
Is current_count < count? Yup.<br>
Get password....<br>
Is password unicorn? Nope.<br>
Is current_count < count? Yup.<br>
Get password....<br>
Is password unicorn? Nope.<br>
Is current_count < count? Nope.<br>
Get password....<br>
better print "That must have been complicated"<br>
Now exit the loop<br>
<br>
you need is to check out the break command in a while loop - <br>
<br>
<br>
while 1 == 1:<br>
x = raw_input('Secret? ')<br>
if x == 'foo':<br>
print 'broke'<br>
break<br>
else:<br>
print 'loopy, loopy'.<br>
<br>
print 'ended loop'<br>
<br>
<br>
Regards, <br>
<br>
Liam Clarke<br>
<br><br><div><span class="gmail_quote">On Apr 12, 2005 6:54 AM, <b class="gmail_sendername"><a href="mailto:glaevsky@ece.neu.edu">glaevsky@ece.neu.edu</a></b> <<a href="mailto:glaevsky@ece.neu.edu">glaevsky@ece.neu.edu</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hey all,<br><br>Sorry for the bother, thanks for the help.<br><br>I'm trying to write a password guessing program to keep track of<br>how many times the user has entered the password wrong.<br>If it is more than 3 times, print ``That must have been complicated.''<br><br>Following is what I got. If I type "unicorn" it goes straight to "welcome<br>in." Great. But after my third mistake, it just loops in "That must have<br>been complicated."<br><br>I'd like for someone to tell me "why" i screwed up. Not to just fix it.<br><br>Thank you so much in advance. And to give you a little smile for a Monday,<br>I've been working on this for days....argh<br><br>#first of all, why does this have to be here?<br>password="foobar"<br><br>count=3<br>current_count=0<br><br>while password !="unicorn":<br> if current_count<count:<br> password=raw_input("Password:")<br> current_count=current_count+1<br> else:<br> print "That must have been complicated"<br><br>print "Welcome in"<br>Best,<br><br>Gary<br><br>Gary Laevsky, Ph.D.<br>Keck Facility Manager, CenSSIS<br>Northeastern University<br>302 Stearns<br>360 Huntington Ave.<br>Boston, MA 02115<br>voice(617) 373 - 2589<br><br>fax(617) 373 - 7783<br><br><br><br><a href="http://www.censsis.neu.edu">http://www.censsis.neu.edu</a><br><br><a href="http://www.ece.neu.edu/groups/osl">http://www.ece.neu.edu/groups/osl</a><br><br><a href="http://www.keck3dfm.neu.edu">http://www.keck3dfm.neu.edu</a><br><br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br><br><br>-- <br>'There is only one basic human right, and that is to do as you damn well please.<br>And with it comes the only basic human duty, to take the consequences.'