[Techtalk] Python question

Rosie Nelson rosie at normalgrrl.com
Mon Apr 22 09:00:24 EST 2002


>It prints "Welcome in" endlessly, which is the same as one of my
>solutions. I tried putting in a break or return after the print "Welcome
>in." but Python didn't like it.


I've never done any programming in Python before, either.. but here's an idea:

It's going to print "Welcome in" as long as the password was typed in 
correctly and count is less than 3. You don't want to make count equal to 
3, because then it will print that it failed as well! But what would happen 
if you set count to, say, 4 after  printing "Welcome in"? That would break 
the while loop and, at the same time, would keep it from printing "Failed 
three times."

So.. I guess the program would look something like this (my syntax might be 
wrong, though):

#!/usr/bin/python
password = "foobar"
count = 0
     while (count < 3) :
         if(password!="unicorn") :
             password=raw_input("Password : ")
             count = count + 1
         else :
             print "Welcome in."
             count = 4
     if(count == 3) :
         print "Failed three tries."


--


So.. maybe that's what the problem is? That would be my best guess.. =\ 
Experimenting with that idea might help you out..


Rosie Nelson - rosie at normalgrrl.com
"I walk alone and sing to myself. I walk
alone in my own personal hell. A place I
call home, it's a place I dwell." --DBS
http://iloveochxc.livejournal.com/
icq 2559739 - aim peaceloveanddoom




More information about the Techtalk mailing list