How to ask a string again if the wrong answer is entered?
<p>I'm trying to get a string to keep repeating if the answer is wrong. How would I go about doing this? The code I have is below which works but doesn't repeat the answer.</p>

<pre><code>print("Hello there, what is your name?")
MyName = input()
print ("Nice to meet you " + MyName)
print ("What is 2 + 2?")

answer = input()
if answer is '4':
    print("Great job!")
elif answer != '4':
    print ("Nope! please try again.")
while answer != '4':
    print ("What is 2 + 2?")
    break
</code></pre>

<p>You only need the wrong-answer check as loop condition and then output the "great job" message when the loop is over (no <code>if</code> is needed):</p>

<pre><code>print("Hello there, what is your name?")
MyName = input()
print ("Nice to meet you " + MyName)
print ("What is 2 + 2?")
answer = input()
while answer != '4':
    print ("Nope! please try again.")
    print ("What is 2 + 2?")
    answer = input()

print("Great job!")
</code></pre>

python