I have a palindrome: 'Mr. Owl ate my metal worm
'
Below is my code giving me output as False
.
def is_palindrome(value):
lower = value.lower()
return value == value[::-1]
print(is_palindrome(input('Enter the value: ')))
How can I improve my code, making it ignore case, spaces, and special characters, to identify the above palindrome and give the output as True
?
I found that there are a few issues in your code.
value.lower()
to lower
but you did not use lower
.I edited your code so that it returns True, as follows:
def is_palindrome(value):
value = ''.join(value.split())
value = value.replace('.', '')
value = value.lower()
return value == value[::-1] # mrowlatemymetalworm
print(is_palindrome(input('Enter the value: ')))