FW: [Tutor] while loops,password
Rob
rob@uselesspython.com
Wed, 14 Aug 2002 07:39:22 -0500
-----Original Message-----
From: thomi@thomi.imail.net.nz [mailto:thomi@thomi.imail.net.nz]
Sent: Wednesday, August 14, 2002 7:15 AM
To: Rob
Subject: Re: [Tutor] while loops,password
On Wed, Aug 14, 2002 at 07:08:28AM -0500, Rob wrote:
umm..
> password = "foobar"
what is this bit for?? seems to do nothing to me :-) also.. (scroll
down)
> a=0
>
> while password != "unicorn":
> print "You've guessed",a,"times."
> password = raw_input("Password?:")
> a=a+1
>
> if password=="unicorn":
> print "Welcome in, you took ", a, "attempts."
>
> #I added
> elif a>3:
> break
>
> The *break* breaks out of the while loop.
>
surely you want it to break if you got the answer right aswell?? the way
i see it, and this is probably wrong, it should go something like this:
password='hithere23'
tries=0
instring = ''
while instring != password:
print 'You've guessed %d times!' % (tries)
instring = raw_input('Password: ')
tries=tries+1
if instring == password:
print 'Welcome! you took %d tries!' % (tries)
break
elif tries > 3:
print 'maximum number of tries exceeded!'
break
so yeah, what do you think?? does that look better?? i dunno....hmmmmm
--
The software required Win95 or better, so I installed Linux.
Thomi Richards,
thomi@imail.net.nz