Hey Gary
password="foobar"
#######
the variable password has to be here because you are referiencing before the assignment inside the while sentence. You can also set it to password="" and still will work because you have to tell (in this example) that password is a reserved word(variable)
########
count=3
current_count=0
#######
Here you have two options:
Option 1:
while password !="unicorn":
if current_count<count:
password=raw_input("Password:")
current_count=current_count+1
else:
current_count=2
print "That must have been complicated"
print "Welcome in"
Add this line inside the "else" clause: current_count=2 ####This will make you have more chances and if you fail it will complain.
The problem is that current_count doesn't decrement in the loop, so let's say you fail 3 times the current_count will keep looping because its value is 3 and it won't change in your code. Also I think that if you're making an application to restrict the error to 3 times you may want to finish the app to start over so in that case you may want to try option 2.
#######
Option 2:
while password !="unicorn" and current_count <= count:
if current_count<count:
password=raw_input("Password:")
current_count=current_count+1
else:
current_count=current_count+1
print "That must have been complicated"
if password="unicorn":
print "Try again Later"
else:
print "Welcome in"
Here you will lock your prog when the user fails 3 times and will print your line once and then will jump to Try Again later and it will finish
Hope that helps
Regards
Alberto
>From: [EMAIL PROTECTED] >To: tutor@python.org >Subject: [Tutor] Cell Bio Newbie Here >Date: Mon, 11 Apr 2005 14:54:37 -0400 > >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@python.org >http://mail.python.org/mailman/listinfo/tutor
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor