[Tutor] Cell Bio Newbie Here

Sean Fioritto sean.fioritto at gmail.com
Mon Apr 11 21:16:30 CEST 2005


The reason you are looping forever is because you are not resetting
current_count to zero.

Let's step through your logic, assume that current_count = 2 
- you enter into the if part of your logic
- prompt the user for a password
- user enters a password, let's assume it's not unicorn, and you store
that in password
- current_count is incremented by one so it's now 3

- go to the top of the while loop, password is not equal to unicorn
- current count is = to 3, so we enter the else
- print "That must have been complicated"

Go to the top of the while loop
our password was never changed so we enter the while loop
current_count was never changed(it is still 3), so we go into the else statement
print print "That must have been complicated"

go to the top of the while loop
...and you see that we're stuck.

underneat this line, and within the else you need to add a line to
reset current_count

It will look like this:
else:
   print "That must have been complicated"
   curent_count = 0

So now when current_count == 3
go to the top of the while loop
password is wrong so go into the loop
current_count is not less than count so go into the else statement
print "That must have been complicated"
current_count is now 0

- go to the top of the while loop
- you enter into the if part of your logic because current_count is
less than count
- prompt the user for a password
- user enters a password, let's assume it's not unicorn, and you store
that in password
- and so on...

I'm pretty sure that fixes it. Good luck!

- Sean



On Apr 11, 2005 11: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
>


More information about the Tutor mailing list