Loop Question

Chris “Kwpolska” Warrick kwpolska at gmail.com
Mon Jun 24 14:53:06 EDT 2013


On Mon, Jun 24, 2013 at 8:42 PM, John Gordon <gordon at panix.com> wrote:
> In <e41ce3a3-c8cb-4cfc-ba86-462f40f322fc at googlegroups.com> christhecomic at gmail.com writes:
>
>> On Sunday, June 23, 2013 6:18:35 PM UTC-5, christ... at gmail.com wrote:
>> > How do I bring users back to beginning of user/password question once they
>> >
>> > fail it? thx
>
>> Can't seem to get this to cooperate...where does the while statement belong?
>
> while True:
>     username = raw_input("Please enter your username: ")
>     password = raw_input("Please enter your password: ")
>
>     if username == "john doe" and password == "fopwpo":
>         print "Login Successful"
>         break
>
>     else:
>         print "Please try again"

You didn’t test the code, did you?  Because the code you posted is
right.  Remember to always test code before submitting.  And note that
the getpass module is what you should use for that second thing in
real life, for the security of your users.

--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html



More information about the Python-list mailing list