[Tutor] (no subject)

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 12 Aug 2002 09:56:55 -0700 (PDT)


On Mon, 12 Aug 2002, akira sugiura wrote:

> I am completly new to either python or a world of programing. Honestly I
> am a bit nervous using this service first time. Anyway whilst I've tried
> to solve this exercise but couldn't get to the answer. Can anyone help?

Hi Akira,

Welcome aboard!  Just wondering: what book or web site are you using?



> ======================================================
> Modify this program to keep track of how many times
> the user has entered the password wrong. If it is more
> than 3 times, print ``That must have been
> complicated.''
>
> password = "foobar"
>
> while password != "unicorn":
>     password = raw_input("Password:")
> print "Welcome in"
> =======================================================


You may want to try to simplify the problem.  How about modifying your
program to print how many times the user has tried to guess?  We can
imagine working with it like:

###
You've guessed 0 times.
Password: foobar
You've guessed 1 times.
Password: marshmellow
You've guessed 2 times.
Password: mellon
You've guessed 3 times.
Password: xyzzy
You've guessed 4 times.
Password: unicorn
###

If we remove that '3 times' restriction, that may be easier write, and
you'll get a better feel for loops.

The problem with the original question is that it's asking for two things
--- loops and conditionals --- and dealing with both at the same time can
be intimidating at first.  Instead, let's take things one at a time.


Please feel free to ask more questions, and if you see stuff on Tutor
that's confusing, please tell us that we're just not making sense.
*grin* Also, when you reply to a message here, make sure to send to
'tutor@python.org', so that all of us here can help you.  Good luck to
you!