[Techtalk] Python (resent)

Terri terri at zone12.com
Fri Apr 26 15:50:08 EST 2002


This bounced back at me.  I imagine it's not useful now, but I thought I'd
resend just to make sure there wasn't some problem on this end causing it to
fail...

Return-path: <terri at terri.zone12.com>
Received: from terri by ostraya.zone12.com with local (Exim 3.35 #1 (Debian))
	id 16zgeC-00007c-00; Mon, 22 Apr 2002 12:26:36 -0400
Date: Mon, 22 Apr 2002 12:26:36 -0400
From: Terri <terri at zone12.com>
To: BUNTER MATTHEW <Matthew.Bunter at renaultvi.com>
Cc: TECHTALK at linuxchix.org
Subject: Re: [Techtalk] Python question
Message-ID: <20020422162635.GA445 at ostraya.zone12.com>
References: <200204221455.ZhN5 at memorvi>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <200204221455.ZhN5 at memorvi>
User-Agent: Mutt/1.3.28i
Sender: Terri Oda <terri at terri.zone12.com>

> #!/usr/bin/python
> password = "foobar"
> 
> while password!="unicorn":
>     password=raw_input("Password : ")
> print "Welcome in."
> 
> I have tried the script with for loops, with another while loop and nothing
> works. Can someone suggest something or I am doomed from the start to
> accept that I will never be able to program anything as simple as I am sure
> this solution is!!!!!!!!!!!!!!

Not sure if you just want a solution to look at or a pointer to the
solution... the pointer is that a for or a while loop would do, but you
probably just had your loops a bit messed up.  

Here's my solution, tested and all.  Not exactly a thing of beauty, but I
hope it's clear how it works.  If it needs explanation, let me know.

#!/usr/bin/python
password = "foobar"

count = 0

while count < 3 and password != "unicorn":
        password=raw_input("Password: ")
        count = count + 1

if password=="unicorn":
        print "Welcome in"
else:
        print "Too many tries.  Exiting."

----- End forwarded message -----



More information about the Techtalk mailing list