Modify the guess My Number program given below. Modify it so that now the player has only five guesses. If the player runs out of guesses, the program should end the game and display an appropriately chastising message.

Guess My Number

The computer picks a random number between 1 and 100

The player tries to guess it and the computer lets

the player know if the guess is too high, too low

or right on the money

import random
print "\tWelcome to 'Guess My Number'!"
print "\nI'm thinking of a number between 1 and 100."
print "Try to guess it in as few attempts as possible.\n"

set the initial values

the_number = random.randrange(100) + 1
guess = int(raw_input("Take a guess: "))
tries = 1

guessing loop

while (guess != the_number):
if (guess > the_number):
print "Lower..."
print "Higher..."
guess = int(raw_input("Take a guess: "))
tries += 1
print "You guessed it! The number was", the_number
print "And it only took you", tries, "tries!\n"
raw_input("\n\nPress the enter key to exit.")

4 Years
Discussion Span
Last Post by Max00355

Use the Code tags, and also you need to figure out how to do this on your own. We aren't going to just give you the answer.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.