[Tutor] (no subject)
alan.gauld@bt.com
alan.gauld@bt.com
Wed, 14 Aug 2002 15:23:47 +0100
> 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
> if a>3:
> print "That must've been complicated"
> =======================================================
Thats exactly right, well done.
( Actually since I think you started with a=0 you might
want to change the test to if a >=3 but thats nitpicking
:-)
> So, this "while loop" ends only when I enter
> unicorn.(right?)
> How can I make it ends either when I enter "unicorn"
> (right password) or wrong password more than three
> times?
The wrong password will cause 'a' to be incremented thus
you can exit when a >= 3 or, to reverse the logic,
keep the loop going while a < 3.
So just combine the tests using the 'and' operator:
while (passwd != "unicorn") and (a < 3):
# do your thing here....
HTH,
Alan g.