[Tutor] Fwd: Noob requesting help...

Marc Tompkins marc.tompkins at gmail.com
Sun Feb 17 01:59:59 CET 2008


Sorry, I ALWAYS forget to hit 'Reply All'...

On Feb 16, 2008 3:18 PM, John Luke <crunchman2600 at gmail.com> wrote:

> I understand *what's* going on, but I don't understand *why* it's
> happening. To be more specific, I don't understand why the actual password,
> "unicorn", is what it is, even though I set the password to
> "foobar"(password = 'foobar'), and later even stated that the password
> wasn't "unicorn"(while password != 'unicorn':). Any help would be greatly
> appreciated. Thanks!
>

The "while" loop is saying: get input from the user, and as long as the
response does NOT equal "unicorn", keep looping.

You can't check the value of a variable that doesn't exist yet, so the line
'password = "foobar" ' merely served to to create/initialize the 'password'
variable.  Faced with a similar situation, I would have said ' password = ""
' to avoid exactly this sort of confusion.  In fact, I would have done
something like the following:

tmp_str = ""   # this creates the variable so we can check against its value
later on
password = "unicorn"
while tmp_str != password:
    tmp_str =raw_input("Password: ")
print "Welcome in"

I hope that makes things a bit clearer...


-- 
www.fsrtechnologies.com



-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080216/0f9a6ea4/attachment.htm 


More information about the Tutor mailing list