[Techtalk] Python question

BUNTER MATTHEW Matthew.Bunter at renaultvi.com
Mon Apr 22 17:29:00 EST 2002


--- Reçu de       VITEUR.BUNTERMA 04 72 96 57 77            22/04/02 17.29

Mandi,

Yeah tried something like this. It works BUT

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.

Rgs,

Matt

--------------------------------------------------------------------------

Date: Mon, 22 Apr 2002 11:31:46 -0400
Subject: Re: [Techtalk] Python question

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

---- 22/04/02 17.29 ---- Envoyé à      -----------------------------------
 CC:
  -> TECHTALK(a)linuxchix.org



More information about the Techtalk mailing list