The course requires you to build a rather simple word guesser so I wanted to expand on it a little bit.
Is this any good? Are there better way to do the things below?
Is using this many else and ifs inside a while a smart thing to do or should it be avoided generally?
Bonus question: How would you check if raw_input is actually a number? In case the user entered something else.
from random import randint # Generates a number from 1 through 10 inclusive random_number = randint(1, 10) guesses_left = 4 # Start your game! print "Welcome to number guesser!" print "Pick a number from 1 to 10." print "You get 4 tries, choose wisely." print while guesses_left != 0: guess = int(raw_input("Enter your guess: ")) if guess > 10 or guess == 0: print print "Can't read the instructions, huh?" print elif guess == random_number: print print "Congratulations, you win!" break else: guesses_left -= 1 if guesses_left == 0: print "Ha! You lose, sorry." else: if guesses_left == 1: print print "Wrong, guess again." print "This is your final guess, pick carefully." print else: print print "Wrong, guess again." print "Guesses left: %s" % guesses_left print