[Tutor] Newbie Question Again
alan.gauld@bt.com
alan.gauld@bt.com
Fri, 26 Jul 2002 14:18:28 +0100
> We have only studied the While and the If statements so far.
> We haven't studied lists yet.
# Modify the password guessing program to keep track of
# ...If it is more than 3 times, print "That must have
# been complicated."
Password.py
> password = "foobar"
count = 0 # initialise to zero
> while (password != "unicorn") \
and (count < 3): # did you do compound expressions yet?
> password = raw_input("Password:")
count = count + 1 # add one each time round the loop
if count == 3: # we ran out of guesses
print "That must have been complicated"
else: # we must have guessed it
> print "Welcome in"
> I don't understand how to count the users input
Just increment a counter inside the loop
You effectively count the number of iterations rather
than the number of guesses, but since we only have
one guess per iteration thats OK...
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld