Number-guessing game
import random should be at the top of the script.



The call to main should be guarded by if __name__ == "__main__":.



the_number and guess are already int, so the repeated calls to e.g. int(the_number) are redundant.



Docstrings should be formatted properly, as multi-line strings """ """ not comments #. Many of the actual comments are redundant - it's generally obvious what's going on (well done!)



The step argument to ask_number doesn't make much sense, and there's no error handling for non-numeric inputs.



The "magic numbers" 1 and 100 should be factored out.



Use str.format for combining strings with other objects.



Think about your logic more carefully - if guess isn't equal to or greater than the_number it must be less, you can just use else.



100 isn't in range(1, 100).



I would write it as:

import random  

def main(low=1, high=100):
    """Guess My Number

    The computer picks a random number between low and high
    The player tries to guess it and the computer lets
    the player know if the guess is too high, too low
    or right on the money

    """
    print("Welcome to 'Guess My Number'!")
    print("I'm thinking of a number between {} and {}.".format(low, high))
    print("Try to guess it in as few attempts as possible.")

    the_number = random.randint(low, high)
    tries = 0

    while True:
        guess = ask_number("Enter your guess:", low, high)
        if guess == the_number:
            print("You're right on the money!")
            break
        elif guess &gt; the_number:
            print("Too high!")
        else:
            print("Too low!")
        tries += 1

    print("You guessed it! The number was {}.".format(the_number))
    print("And it only took you {} tries!".format(tries))
    input("Press the enter key to exit.")

def ask_number(question, low, high):
    """Get the user to input a number in the appropriate range."""
    while True:
        try:
            response = int(input(question))
        except ValueError:
            print "Not an integer"
        else:
            if response in range(low, high+1):
                return response
            print "Out of range"

if __name__ == "__main__":
    main()




To play again, you could recursively call main, or have a loop at the end of the script:

if __name__ == "__main__":
    while True:
        main()
        again = input("Play again (y/n)? ").lower()
        if again not in {"y", "yes"}:
            break