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>There are a couple of things wrong with your code. Firstly, you are only asking for the answer once at the moment. You need to put <code>answer = input()</code> in a <code>while</code> loop. Secondly, you need to use <code>==</code> instead of <code>is</code>:</p>

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

answer = 0

while answer != '4':

    answer = input()
    if answer == '4':
        print("Great job!")
    else:
        print ("Nope! please try again.")
</code></pre>

<p>There are a number of ways you can arrange this code. This is just one of them</p>

python