I'm able to create a guessing number game, but I can limit the amount of guesses to less than 3. Can someone tell me what i'm doing wrong?
Code:
# Guess My Number
# The computer picks a random number
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..."
else:
print "Higher..."
guess = int(raw_input("Take a guess: "))
if tries > 3:
print "You have more than 3 attempts, game over."
tries += 1
else:
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.")
Comment