"Guess my Number" game in Python (2.7.9)
Magic numbers

1, 10, and 5 are so-called magic numbers in the code: they are duplicated in many places. The numbers themselves don't carry a meaning, but they are special to the program. If you wanted to change the maximum number of tries, you would have to manually search and replace all occurrences of 5. If the number 5 is used for other than the purpose of maximum number of tries, then the change will be especially difficult, as you would have to review each occurrence to verify its purpose.

The solution is simple: give the magic numbers meaningful names, for example:

lower_limit = 1
upper_limit = 10
max_tries = 5


You might even want to make these constants by uppercasing the names.

Copy-paste coding

This piece of code appears multiple times:


remaining = 5 - tries
print("\nYou have " + str(remaining) + " guesses left.\n")



Most probably you copy-pasted it every time you needed.
Try to avoid pressing ControlV while programming.
Try solution is almost always to create a new function, for example:

def print_remaining_guesses(tries):
    remaining = max_tries - tries
    print("\nYou have " + str(remaining) + " guesses left.\n")


Use "{}".format(...) for formatting

Instead of:


print("\nYou have " + str(remaining) + " guesses left.\n")



The recommended way is:

print("\nYou have {} guesses left.\n".format(remaining))


This is a kind of templating. By removing + varname + from the middle of strings, the text becomes a bit easier to read. Another benefit is that you can drop the str(...) wrapper, format will automatically take care of that for you.

Pull common operations up

Looking at this code:


if guess &gt; 10:
    tries += 1
    print("\nWay too high! Try a number 10 or lower.")
else:
    tries += 1
    print("\nTry something lower.")



The value of tries will be increment no matter what. So you can pull it up, out of the if-else:

tries += 1
if guess &gt; 10:
    print("\nWay too high! Try a number 10 or lower.")
else:
    print("\nTry something lower.")


Keep try blocks small

You have a very large try block here:


try:
    guess = int(guess)

    # ... many lines ...

# Input not an integer
except ValueError:
    # ...



Since the only place where you expect something to go wrong is the guess = int(guess) line, it would be better to wrap only that in the try-except.

Comparison with boolean values

Don't use == or != with boolean values. Instead of:


while correct == False:



The recommended way is:

while not correct:


Pointless comments

The comments on these lines really don't tell anything new:


if guess == number:  # Correct answer
    # ...

elif guess &gt; number:  # Guess too high



Let the code speak for itself. Then you really don't need comments at all.

Formatting

The space between print and ( is redundant, you should remove it:


print ("I'm thinking of a number between 1 and 10.")



Python has an official style guide called PEP8, I suggest to review it and follow it.