Code Review and Mastermind Game Question
<p>I'm trying to teach myself Python and found a couple of exercises online. One of which is to design a Mastermind type game <a href="http://www.cse.msu.edu/~cse231/PracticeOfComputingUsingPython/03_Strings/Mastermind/project04.pdf" rel="nofollow">here</a>.</p>

<p>With the help of SO, I have managed most to do most of the requirements but I'm stuck at the last bit. I don't know how I can persist the display of previous guess values, variable <code>msg1</code>, with each new guess.</p>

<p>This is my code snippet to date. Any comments are welcomed!</p>

<pre><code>def position(x, y):
    position = sum(1 for a,b in zip(x ,y) if (a == b))
    return position

def exists(x, y): 
    exists = len(set(x) &amp; set(y))
    return exists

checks = [
    lambda n: (len(n)==4, "Enter 4 digits only."),
    lambda n: (n.isdigit(), "Enter digits only."),
    lambda n: (len(set(str(n)))==4, "Enter non duplicate numbers only.")
]

a = raw_input("Enter the 4 numbers you want to play with: ") 

sturn = 1 
lturn = 8 #this set the maximum number of turns

while sturn &lt;= lturn:
    b = raw_input("Enter your guess: ")
    all_good = True

    for check in checks:
        good, msg = check(b)

        if not good:
            print msg
            all_good = False
            break

    if int(b) == int(a):
        print ("You guessed the key {0}! It took you {1} tries").format(a, sturn)

    if sturn ==  lturn and int(b) != int(a):
        print ("You lose. The answer was {0}").format(a)

    elif int(b) != int(a) :
        msg1 = ("{0}: position:{1}, exists {2}").format(b, position(a, b), (exists(a, b) - position(a, b)))
        print msg1
        sturn += 1
</code></pre>
