First Summer 2006


Lab Three: The end of the beginning.
In lab today we will want to show you (briefly)

The program we will play with will be:

# 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.


Last updated: May 11, 2006 by Adrian German for A201/A597