[Tutor] while loops,password

Rob rob@uselesspython.com
Wed, 14 Aug 2002 07:08:28 -0500


password = "foobar"
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.

You *guess* you're enjoying learning Python? hehe. If there's anything we
can do to make it more enjoyable, let us know. This *should* be kinda fun,
IMO.

Rob
http://uselesspython.com

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> akira sugiura
> Sent: Wednesday, August 14, 2002 6:14 AM
> To: Tutor@python.org
> Subject: [Tutor] while loops,password
>
>
> Thank you Alan,
> =======================================================
> password = "foobar"
>  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
>   if a>3:
>       print "That must've been complicated"
> =======================================================
> 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?
> Probably I will learn it after I advanced more
> practices not now.
>
> Thanks anyway. I am enjoying learning python.(I guess)
>
>
> =====
> -----------------------------------
> Akira Sugiura
> kodokuchef@yahoo.com
> -----------------------------------
>
> __________________________________________________
> Do You Yahoo!?
> HotJobs - Search Thousands of New Jobs
> http://www.hotjobs.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>