An online MIT course which I downloaded ask's its students to create a function to test if a string is a palindrome. They mention len
and only taking a slice of the string. As I understand the assignment I used neither, but my code seems to work.
Is there something I am missing?
def test_word():
question = input("Do you want to see if a word or sentence is a
palindrome? (y/n)")
question = question.lower()
if question == "y":
sample = input("Provide test word or sentence: \n>>>")
sample = sample.lower()
print(is_palindrome(sample))
test_word()
elif question == "n":
print("Goodbye!")
quit()
else:
print("Y for yes or N for no, please.")
test_word()
def is_palindrome(x):
# Use negative 1 step to reverse order
y = x[::-1]
if x == y:
return True
elif x != y:
return False
test_word()