I am currently taking a course on Python and am currently struggling with one portion of my homework.
The question is asking us to construct a function that checks a string to see if it is a palindrome. The problem I am having is that for one of the tests my instructor has provided is for the palindrome "Never odd or even" which contains spaces. The spaces are causing my function to fail because it won't just use the letters in the phrase.
My current code is:
return phrase == phrase[::-1]
assert is_palindrome("Never odd or even")
I think this is what you want:-
is_palindrome("Never odd or even".replace(" ", "").lower())
If you want to change your function then your function look like:
def is_palindrome(phrase): phrase=phrase.replace(" ","").lower() return phrase == phrase[::-1]
and you can call it using
is_palindrome("Never odd or even")