Computer guessing game
<pre><code>import random

def start():
    print "\t\t***-- Please enter Y for Yes and N for No --***"
answer = raw_input("\t\t    Would you like to play a Guessing Game?: ")
if answer == "Y"
or answer == "y":
    game()
elif answer == "N"
or answer == "n":
    end()

def end():
    print("\t\t\t     **Goodbye** ")
raw_input("\t\t\t**Press ENTER to Exit**")

def game():

    print "\t\t\t  Welcome to Williams Guessing Game"
user_name = raw_input("\n\t\t  Please enter your name: ")
print "\n", user_name, "I am thinking of a number between 1 and 20"
print "You have 5 attempts at getting it right"
attempt = 0
number = random.randint(1, 20)

while attempt &lt; 5:
    guess = input("\t\nPlease enter a number: ")
attempt = attempt + 1
answer = attempt
if guess &lt; number:
    print "\nSorry", user_name, "your guess was too low"
print "You have ", 5 - attempt, " attempts left\n"
elif guess &gt; number:
    print "\nSorry ", user_name, " your guess was too high"
print "You have ", 5 - attempt, " attempts left\n"
elif guess == number:
    print "\n\t\t Yay, you selected my lucky number. Congratulations"
print "\t\t\tYou guessed it in", attempt, "number of attempts!\n"
answer = raw_input("\n\t\t\t\tTry again? Y/N?:  ")
if answer == "Y"
or answer == "y":
    game()
elif answer == "N"
or answer == "n":
    end()

start()
</code></pre>

<p>If you want the computer to guess your number, you could use a function like this:</p>

<pre><code>import random

my_number = int(raw_input("Please enter a number between 1 and 20: "))
guesses = []

def make_guess():
    guess = random.randint(1, 20)
    while guess in guesses:
        guess = random.randint(1, 20)
    guesses.append(guess)
    return guess

while True:
    guess = make_guess()
    print(guess)
    if guess == my_number:
        print("The computer wins!")
        break
    else:
        print(guesses)
</code></pre>

<p>It's just a quick-and-dirty example, but I hope it gives you the idea.  This way, the computer gets unlimited guesses, but you could easily change the <code>while</code> loop to limit its number of guesses.</p>

python