Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active Jul 16, 2021
Embed
What would you like to do?
Python / Language / Palindrome - https://www.minte9.com/python/math-development-1257
# Write a function called is_palindrom
# You can use built-in funciton len to check the string length
# A palindorm is a word that is spelled the same backward and forward
# Example: noon, redivider
def first(word): return word[0]
def last(word): return word[-1]
def middle(word): return word[1:-1]
# SOLUTION
def is_palindrome(word):
if (first(word) != last(word)):
return False
if (len(word) > 2):
return is_palindrome(middle(word))
return True
print(is_palindrome("noon")) # True
print(is_palindrome("redivider")) # True
print(is_palindrome("to")) # False
print(is_palindrome("moomm")) # False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment