Francis Girard:
Here is the code you are looking for if I read you right:
# Michael Dawson -
1/8/03
import random print "\tWelcome to 'Guess My Number'!" print "\nI'm thinking of a number between 1 and 10." # I have randrange set to 10 for debugging. 3 is even faster. print "Try to guess it in under three attempts.\n" # set the initial values counter = 1 # I had to set counter to = 1 for this to work right. the_number = random.randrange(10) + 1 # but it is bug free. guess = int(raw_input("Take a guess: ")) # guessing loop while (guess != the_number): if counter >= 3: # this statement had to go up top print 'Game over! Your 3 tries are up.' break # OKAY! Using break after "game over" is perfect! elif (guess > the_number): print "Lower..." else: print "Higher..." counter += 1 guess = int(raw_input("Take a guess: ")) else: print "You guessed it! The number was", the_number if counter >=2: print "And it only took you", counter, "tries!\n" else: print "and it only took you 1 try!\n" # check this out! # this solution sure took me long enough! What I can't help you with # is how great it would make you feel to do it yourself.
# a fellow newbie.
|
-- http://mail.python.org/mailman/listinfo/python-list