athira babu athira babu - 1 year ago 109
Python Question

Returning result of palindrome program using while-loop

n = str(input('Enter the string:'))
def palindrome(n):
index = 0
check = True
while index<int(len(n)/2):
if n[index]==n[-1-index]:
return True
return False
if palindrome(n)==True:
print('not palindrome')

I am not getting the correct answer for this palindrome program.

Answer Source

The classic solution:

def palindrome(n):
    start = 0
    end = len(n) - 1
    while (start < end):
        if (n[start] != n[end]):
            return False
        start = start + 1
        end = end - 1
    return True
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download