|
First Summer 2006 |
# Guess my number.
import random
num = random.randrange(100) + 1
print "The secret number is " + str(num)
tries = 0
while True:
guess = int(raw_input("What is the secret number? (" + str(num) + ") "))
if guess > num:
print str(tries+1) + ": Try lower."
elif guess < num:
print str(tries+1) + ": Try higher."
else:
print "You guessed it! In " + str(tries + 1) + " attempts."
break
tries += 1
if tries >= 5: # number of tries allowed
print "Sorry, you lost."
tries = 0
num = random.randrange(100) + 1
raw_input("Press Enter if you liked the game.")
Our focus is on compiling and especially running this program. Interacting with it is our main goal now.
Learning how it develop it will come much later.
Once this is clear you can and should work on the two new homework assignments posted today.