Nested structures question
Tim Harig
usernet at ilthio.net
Wed Jan 12 17:19:25 EST 2011
In case you still need help:
- # Set the initial values
- the_number= random.randrange(100) + 1
- tries = 0
- guess = None
-
- # Guessing loop
- while guess != the_number and tries < 7:
- guess = int(raw_input("Take a guess: "))
- if guess > the_number:
- print "Lower..."
- elif guess < the_number:
- print "Higher..."
- tries += 1
-
- # did the user guess correctly to make too many guesses?
- if guess == the_number:
- print "You guessed it! The number was", the_number
- print "And it only took you", tries, "tries!\n"
- else:
- print "Wow you suck! It should only take at most 7 tries!"
-
- raw_input("Press Enter to exit the program.")
More information about the Python-list
mailing list