[Tutor] Cell Bio Newbie Here

Liam Clarke cyresse at gmail.com
Mon Apr 11 22:00:32 CEST 2005


Hi Gary, 

In a while loop, you could looping until the while condition is no longer 
true.
So your one - 


while password != "unicorn"

So while password isn't unicorn, your condition is True, so your while loop 
will keep looping until the password equals 'unicorn'

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. 

Python goes 

Is password unicorn? Nope.
Is current_count < count? Nope.
better print "That must have been complicated"
Is password unicorn? Nope.
Is current_count < count? Nope.
better print"That must have been complicated"
Is password unicorn? Nope.
Is current_count < count? Nope.
better print "That must have been complicated"

if you get the drift. 

If you want it to be

Is password unicorn? Nope.
Is current_count < count? Yup.
Get password....
Is password unicorn? Nope.
Is current_count < count? Yup.
Get password....
Is password unicorn? Nope.
Is current_count < count? Yup.
Get password....
Is password unicorn? Nope.
Is current_count < count? Nope.
Get password....
better print "That must have been complicated"
Now exit the loop

you need is to check out the break command in a while loop - 


while 1 == 1:
x = raw_input('Secret? ')
if x == 'foo':
print 'broke'
break
else:
print 'loopy, loopy'.

print 'ended loop'


Regards, 

Liam Clarke


On Apr 12, 2005 6:54 AM, glaevsky at ece.neu.edu <glaevsky at ece.neu.edu> wrote:
> 
> 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
> 
> #first of all, why does this have to be here?
> password="foobar"
> 
> 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"
> Best,
> 
> Gary
> 
> 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>
> 
> http://www.censsis.neu.edu
> 
> http://www.ece.neu.edu/groups/osl
> 
> http://www.keck3dfm.neu.edu
> 
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



-- 
'There is only one basic human right, and that is to do as you damn well 
please.
And with it comes the only basic human duty, to take the consequences.'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050412/16e86676/attachment.htm


More information about the Tutor mailing list