Returning result of palindrome program using while-loop
<pre><code>n = str(input('Enter the string:'))
def palindrome(n):
    index = 0
    check = True
    while index&lt;int(len(n)/2):
        if n[index]==n[-1-index]:
            index+=1
            return True
            break
        return False
if palindrome(n)==True:
    print('palindrome')
else:
    print('not palindrome')
</code></pre>

<p>I am not getting the correct answer for this palindrome program.</p>

<p>Your check is broken. Look at <code>return True</code>:</p>

<pre><code>def palindrome(n):
    index = 0
    check = True
    while index&lt;int(len(n)/2):
        if n[index]==n[-1-index]:
            index+=1  # only increment on match !!!
            return True  # return True on *first* match !!!
            break  # unnecessary, return exits the loop
        return False  # never reached, but would only trigger if there are no matches
</code></pre>

<p>Basically, you go through your string and on the first <em>match</em> you report True. So if first and last letter are the same, <code>True</code> is returned. Only if <em>no</em> pair of characters matches, you return <code>False</code>. This is the opposite of what want to check. It should be this instead:</p>

<pre><code>def palindrome(n):
    index = 0
    check = True
    while index &lt; len(n)/2:
        if n[index] != n[-1-index]:
            return False  # one didn't match, cannot be a palindrome
        index+=1
    return True  # all did match, is a palindrome
</code></pre>

python