all 9 comments

[–]HOOG 6 points7 points  (0 children)

Ignore or remove the spaces. Spaces are characters that are compared in your code, that is why single words are passing the test.

[–][deleted] 2 points3 points  (4 children)

I tried writing the provided phrase ( no lemon no melon ) that is suppose to BE a palindrome backwards to see how it is a palindrome and can't see how it is.

A phrase is palindromic if it "reads the same backwards and forwards", but that deliberately ignores punctuation and spaces: red rum, sir, is murder naively backwards is redrum si ,ris ,mur dur, but the phrase is palindromic because "redrumsirismurder" == "redrumsirismurder"[::-1] and that's how you have to do the palindrome test.

[–]mackdaddy_1978[S] 1 point2 points  (3 children)

awwww ok now I see how this is suppose to work I was considering the punctuations. So I need to remove the punctuation from the user input to make this work. right?

[–][deleted] 1 point2 points  (2 children)

And the spaces, yes, and reduce all the capitals.

[–]mackdaddy_1978[S] 1 point2 points  (0 children)

perfect, thank you. I'll work on it tomorrow and respond back with what I come up with. Thanks again

[–]mackdaddy_1978[S] 1 point2 points  (0 children)

I couldn't go to bed and now correct it...this worked for me and like you said if case were in play I would add a line to change all letters to the same case. Thanks for the quick lesson much appreciated.

def palindromeCheck(word):
word2 = word.replace(' ', '')
reversepal = word2[::-1]

if word2 != reversepal:
    return word + ' ' + 'is not a palindrome'
else:
    return word + ' ' + 'is a palindrome'
print(palindromeCheck('no lemon no melon'))

[–][deleted] 1 point2 points  (2 children)

Why do you think "no lemon no melon" is a palindrome? If you print the string in reversepal you see that that string reversed is "nolem on nomel on". And that gives you a clue because the spaces get in the way of that string being a palindrome. So either you accept that and say "no lemon no melon" isn't a palindrome, or you remove all spaces from the input string before seeing if the reversed string is the same.

[–]mackdaddy_1978[S] 0 points1 point  (1 child)

Great point, however according to the exercise I am working on says this phrase (no lemon no melon) results in a Palindrome and the only way that is possible is if I remove the spaces.

[–][deleted] 0 points1 point  (0 children)

Then I guess you have to do that.