Guess-the-number game by a Python beginner
This is a good first stab at a guess the number game.

Here's a few things:


You should be learning/using Python 3 instead of Python 2. So far the only difference for you will be raw_input becomes input and print "foo" becomes print("foo").
The line tries = tries doesn't do anything meaningful. You don't need it
You should put all of this inside a function called main and then at the bottom you run it with this (tests if this script is being run standalone):




if __name__ == '__main__':
    main()



You do int(guess) a lot. This is something that can fail (if someone types abc for example). You should do it once and check for failure.




try:
    guess = int(guess)
except ValueError:``
    print('Guess must be between 0 and 25')
    # ask for another guess



It's a good idea to comment. That's a fantastic habit to get into. However, you run the risk of over-commenting. And that is more distracting than having too few. As a rule, don't explain what, explain why. More concretely, "check to see if a user guessed the right number" is obvious from the if guess == secret_number:. Finding a balance is a skill, but if you work on it and read good quality open source code, you'll pick it up.
When you do your range check, you can do it in a much more pythonic way. Instead of checking guess &lt; 0 or guess &gt; 25, you can do if not 0 &lt;= guess &lt;= 25
tries = tries + 1 can be tries += 1
You don't need to escape ' inside a " (so "Congratulations you\'ve won!" can be "Congratulations you've won!")


The overarching issue you have though is most of your logic is duplicated in several different places. This becomes a problem if you want to, say, change the number range from 0-25 to 0-50. You'd need to change that in 6 places. What happens if you miss one? Then your game will break in weird ways.

What's the solution? Look to pull out duplicate logic like this into smaller, manageable chunks. In this case, it's helpful to identify the steps of your game.


Generate a secret number
Collect a guess from the user
If the user guessed the secret or more than 10 attempts have been made, end, else go back to 2


One easy thing you can pull out is "collect a guess from the user." You can do this in a function that gets the number, converts it to an int (handling the exception), and checking it is within range.

LOW, HIGH = 0, 25

def get_guess():
    while True:
        try:
            guess = int(input(f'Guess a number between {LOW}-{HIGH}: '))
        except ValueError:
            print('Please enter a number')
        else:
            if LOW &lt;= guess &lt;= HIGH:
                return guess

            print(f'Number must be between {LOW} and {HIGH}')


Now you can use get_guess() when you need to guess the guess from the user without having to add any extra control structures (like wrapping everything in a while) or duplicate any logic.

Now, when using get_guess() you can concern yourself with fewer facets of the game. Namely, checking the number of attempts and if the guess was correct:

from random import randint

MAX_ATTEMPTS = 10

def main():
    secret = randint(LOW, HIGH)

    for _ in range(MAX_ATTEMPTS):
        guess = get_guess()

        if guess == secret:
            print('You win!')
            break
    else:
        print('Too many attempts; you lose.')