First python program, syntax error in while loop
ryankoch38 at gmail.com
ryankoch38 at gmail.com
Fri May 3 16:15:50 EDT 2013
Thank you! It's 100% functional now, here's the final project:
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) and (tries <5):
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 "\nCongratulations! You guessed my number in", tries, "tries"
else:
print "\nSorry, you took too many tries to guess my number!"
raw_input("\n\n Press any key to exit..")
## Maybe now I can work on a useful project
More information about the Python-list
mailing list