Q:

How do you make use of a counter with recursion in Python?

I'm trying to write a simple "password" program in Python that allows 3 attempts at "logging in" with a recursive function. I can't figure out why it's not working though... (And yes, Jurassic Park inspired)
def magicWord(count):
    int(count)
    answer = raw_input("What is the password? ")
    if answer == 'lucas':
        print 'ACESS GRANTED'
    else:
        count =+ 1
        if count > 2:
            while count > 2:
                count+=1
                print "na na na you didn\'t say the magic word. "
        else:
            magicWord(count)

magicWord(0)

A:

You were very close.  There were just a couple minor fix-ups:
def magicWord(count):
    answer = raw_input("What is the password? ")
    if answer == 'lucas':
        print 'ACESS GRANTED'
    else:
        count += 1
        if count > 2:
            print "na na na you didn\'t say the magic word. "
            return
        else:
            magicWord(count)

Here's a sample session:
>>> magicWord(0)
What is the password? alan
What is the password? ellie
What is the password? ian
na na na you didn't say the magic word.

