Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49009 > unrolled thread
| Started by | christhecomic@gmail.com |
|---|---|
| First post | 2013-06-23 16:18 -0700 |
| Last post | 2013-06-24 15:23 -0400 |
| Articles | 13 — 8 participants |
Back to article view | Back to comp.lang.python
Loop Question christhecomic@gmail.com - 2013-06-23 16:18 -0700
Re: Loop Question rurpy@yahoo.com - 2013-06-23 16:49 -0700
Re: Loop Question christhecomic@gmail.com - 2013-06-23 20:24 -0700
Re: Loop Question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-24 00:23 +0000
Re: Loop Question christhecomic@gmail.com - 2013-06-24 05:12 -0700
Re: Loop Question rusi <rustompmody@gmail.com> - 2013-06-24 07:03 -0700
Re: Loop Question Lutz Horn <lutz.horn@posteo.de> - 2013-06-24 14:20 +0200
Re: Loop Question Dave Angel <davea@davea.name> - 2013-06-25 09:40 -0400
Re: Loop Question christhecomic@gmail.com - 2013-06-24 11:23 -0700
Re: Loop Question John Gordon <gordon@panix.com> - 2013-06-24 18:42 +0000
Re: Loop Question Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-06-24 20:53 +0200
Re: Loop Question John Gordon <gordon@panix.com> - 2013-06-24 19:00 +0000
Re: Loop Question Dave Angel <davea@davea.name> - 2013-06-24 15:23 -0400
| From | christhecomic@gmail.com |
|---|---|
| Date | 2013-06-23 16:18 -0700 |
| Subject | Loop Question |
| Message-ID | <2149a85e-e41b-46bf-a12d-7565789748a9@googlegroups.com> |
How do I bring users back to beginning of user/password question once they fail it? thx
[toc] | [next] | [standalone]
| From | rurpy@yahoo.com |
|---|---|
| Date | 2013-06-23 16:49 -0700 |
| Message-ID | <5718861c-82c8-4878-933e-354e3e76731d@googlegroups.com> |
| In reply to | #49009 |
On 06/23/2013 05:18 PM, christhecomic@gmail.com wrote:
> How do I bring users back to beginning of user/password question once they
> fail it? thx
This is not a very good question. There is no context
so we cannot tell if you are talking about a command line
program that prompts for a username and password or a
GUI program with a text box asking for the user/password
or something else. Nor how exactly you go about doing
the asking.
Some code showing what you are trying to do would help
a lot.
I'll guess you're asking about a simple command line
program. Maybe something like the following is what
you want?
while True:
user = input ("User? ").strip()
pw = input ("Password? ").strip()
if check_user (user, pw): break
print ("Hello %s" % user)
check_user() is a function you'll define somewhere that
checks the user and password and returns True if they are
correct and False if not.
Since you didn't say, I'm also assuming you're using
Python 3; for Python 2 the code will be a little
different.
This is a useful guide to asking questions in a way that
makes it easier for people to answer (and thus help
*you* get better, faster answers):
http://www.catb.org/esr/faqs/smart-questions.html
[toc] | [prev] | [next] | [standalone]
| From | christhecomic@gmail.com |
|---|---|
| Date | 2013-06-23 20:24 -0700 |
| Message-ID | <a27f14d4-9874-4975-a22c-47be5eaa3c75@googlegroups.com> |
| In reply to | #49011 |
I'm using 2.7....
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-06-24 00:23 +0000 |
| Message-ID | <51c7916f$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #49009 |
On Sun, 23 Jun 2013 16:18:35 -0700, christhecomic wrote: > How do I bring users back to beginning of user/password question once > they fail it? thx Write a loop. If they don't fail (i.e. they get the password correct), then break out of the loop. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | christhecomic@gmail.com |
|---|---|
| Date | 2013-06-24 05:12 -0700 |
| Message-ID | <afc4753e-d7b0-46b1-80d4-0e2fe8440871@googlegroups.com> |
| In reply to | #49009 |
Here is my code...I'm using 2.7.5
username=raw_input("Please enter your username: ")
password=raw_input("Please enter your password: ")
if username == "john doe" and password == "fopwpo":
print "Login Successful"
else:
print "Please try again"
[toc] | [prev] | [next] | [standalone]
| From | rusi <rustompmody@gmail.com> |
|---|---|
| Date | 2013-06-24 07:03 -0700 |
| Message-ID | <94c08a50-0a01-4beb-b646-6d6f8c0ed344@googlegroups.com> |
| In reply to | #49041 |
On Monday, June 24, 2013 5:42:51 PM UTC+5:30, christ...@gmail.com wrote:
> Here is my code...I'm using 2.7.5
>
>
> username=raw_input("Please enter your username: ")
> password=raw_input("Please enter your password: ")
> if username == "john doe" and password == "fopwpo":
> print "Login Successful"
> else:
> print "Please try again"
Good!
Now take Steven's suggestion "loop with a break"
and bung your code into Steven's loop.
[Hint: You have to add a break somewhere!]
Or at least try!
[toc] | [prev] | [next] | [standalone]
| From | Lutz Horn <lutz.horn@posteo.de> |
|---|---|
| Date | 2013-06-24 14:20 +0200 |
| Message-ID | <mailman.3824.1372164608.3114.python-list@python.org> |
| In reply to | #49041 |
Hi,
Am 24.06.2013 14:12 schrieb christhecomic@gmail.com:
> username=raw_input("Please enter your username: ")
> password=raw_input("Please enter your password: ")
> if username == "john doe" and password == "fopwpo":
> print "Login Successful"
> else:
> print "Please try again"
while not username or not password or username != "john doe" or
password != "fopwpo":
print "Please try again"
username=raw_input("Please enter your username: ")
password=raw_input("Please enter your password: ")
print "Login Successful"
--
Opt out of PRISM, the NSA’s global data surveillance program.
Stop reporting your online activities to the American government
with these free alternatives to proprietary software.
http://prism-break.org/
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-06-25 09:40 -0400 |
| Message-ID | <mailman.3827.1372167656.3114.python-list@python.org> |
| In reply to | #49041 |
On 06/24/2013 08:20 AM, Lutz Horn wrote:
> Hi,
>
> Am 24.06.2013 14:12 schrieb christhecomic@gmail.com:
>> username=raw_input("Please enter your username: ")
>> password=raw_input("Please enter your password: ")
>> if username == "john doe" and password == "fopwpo":
>> print "Login Successful"
>> else:
>> print "Please try again"
>
> while not username or not password or username != "john doe" or password
> != "fopwpo":
> print "Please try again"
> username=raw_input("Please enter your username: ")
> password=raw_input("Please enter your password: ")
>
> print "Login Successful"
>
>
That requires you to have four raw_input() calls instead of two. And
what purpose does adding the two new clauses to the while test serve?
How is:
while not username or not password or username != "john doe" or password
!= "fopwpo":
different from:
while username != "john doe" or password != "fopwpo":
(other than taking more time and space, and being harder to read) ?
--
DaveA
[toc] | [prev] | [next] | [standalone]
| From | christhecomic@gmail.com |
|---|---|
| Date | 2013-06-24 11:23 -0700 |
| Message-ID | <e41ce3a3-c8cb-4cfc-ba86-462f40f322fc@googlegroups.com> |
| In reply to | #49009 |
On Sunday, June 23, 2013 6:18:35 PM UTC-5, christ...@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?
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2013-06-24 18:42 +0000 |
| Message-ID | <kqa3v3$ddf$1@reader2.panix.com> |
| In reply to | #49061 |
In <e41ce3a3-c8cb-4cfc-ba86-462f40f322fc@googlegroups.com> christhecomic@gmail.com writes:
> On Sunday, June 23, 2013 6:18:35 PM UTC-5, christ...@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"
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | Chris “Kwpolska” Warrick <kwpolska@gmail.com> |
|---|---|
| Date | 2013-06-24 20:53 +0200 |
| Message-ID | <mailman.3754.1372100014.3114.python-list@python.org> |
| In reply to | #49062 |
On Mon, Jun 24, 2013 at 8:42 PM, John Gordon <gordon@panix.com> wrote:
> In <e41ce3a3-c8cb-4cfc-ba86-462f40f322fc@googlegroups.com> christhecomic@gmail.com writes:
>
>> On Sunday, June 23, 2013 6:18:35 PM UTC-5, christ...@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
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2013-06-24 19:00 +0000 |
| Message-ID | <kqa503$369$1@reader2.panix.com> |
| In reply to | #49063 |
In <mailman.3754.1372100014.3114.python-list@python.org> =?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?= <kwpolska@gmail.com> writes:
> > 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.
It's right, therefore I did not test it? I don't understand.
If the code has a bug, please point it out.
> And note that the getpass module is what you should use for that second
> thing in real life, for the security of your users.
I'm sure this is just an exercise for the OP to understand loops. Security
would be counter-productive.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-06-24 15:23 -0400 |
| Message-ID | <mailman.3756.1372101844.3114.python-list@python.org> |
| In reply to | #49065 |
On 06/24/2013 03:00 PM, John Gordon wrote:
> In <mailman.3754.1372100014.3114.python-list@python.org> =?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?= <kwpolska@gmail.com> writes:
>
>>> 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.
>
> It's right, therefore I did not test it? I don't understand.
I expect that Chris simply misinterpreted the quoting in your message,
thinking that the OP had both typed the
"Can't seem to get this to cooperate...where does t..."
and the correct code. In fact, the OP typed the former, and you typed
the latter.
--
DaveA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web