No need for such complex conditional. You already have a reversed string (string[::-1]
).
All you need to do is this:
def isPalindrome():
string1 = input('Enter a string: ')
string2 = string1[::-1]
if string1 == string2:
return 'It is a palindrome'
return 'It is not a palindrome'
isPalindrome()
(by the way don't use string
as a variable name. That's the name of a built-in module)
It's better to return the strings instead of printing them. That way your function will not return None
(preventing some stuff that could happen later)