[Techtalk] Python question

Mandi mandi at linuxchick.org
Mon Apr 22 11:31:46 EST 2002


On Mon, 22 Apr 2002, BUNTER MATTHEW wrote:

>
> #!/usr/bin/python
> password = "foobar"
>
> while password!="unicorn":
>     password=raw_input("Password : ")
> print "Welcome in."
>

I've never programmed python before, but here's something:

-----
#!/usr/bin/python
password = "foobar"
count = 0

while (count < 3) :
    if(password!="unicorn") :
        password=raw_input("Password : ")
        count = count + 1
    else :
        print "Welcome in."

if(count == 3) :
    print "Failed three tries."

-----

It's not pretty, but what it's doing is using the variable "count" to
check for the three tries.  when it matches, you get the "Welcome in."  If
it never matches and drops out of the while loop, it checks the value of
"count" and prints the "Failed three tries." message.

Anyway, I hope that gives you something useful to look at.

--mandi





More information about the Techtalk mailing list