First python program, syntax error in while loop
ryankoch38 at gmail.com
ryankoch38 at gmail.com
Fri May 3 15:52:14 EDT 2013
I've got it working! I'm really enjoying python :) But now i'd like to make it break out of the while loop when the user guesses more than 5 numbers and fails..
title = "Guess my number game:"
print title.title()
raw_input("Press any key to continue..")
import random
number = random.randrange(99) + 1
tries = 0
guess = int(raw_input("Guess my number! Secret - It is between 1 and 100 :"))
while (guess != number):
if (guess > number):
guess = int(raw_input("Sorry, my number is lower than that! \n Try again:"))
tries += 1
if (guess < number):
guess = int(raw_input("Sorry, my number is higher than that! \n Try again:"))
tries += 1
if (tries > 5):
print "Sorry, you lost!"
break
print "\nCongratulations! You guessed my number in", tries, "tries"
raw_input("\n\n Press any key to exit..")
## this results in the congratulations printing after the second/third guess and ## continuing
More information about the Python-list
mailing list