I have modified the following function to return if the given string is a Palindrome. I also have it excluding capitalization, spaces, and punctuation. How can i modify this to return "false" if the user enters a non string.
import string
def remove_punctuations(word):
return "".join(i.lower() for i in word if i in string.ascii_letters)
def reverse(text):
return text[::-1]
def is_palindrome(text):
text = remove_punctuations(text)
return text==reverse(text)
# where I am entering the string
something = "12.5"
if (is_palindrome(something)):
print("True")
else:
print("False")
# some test cases
>>> isPalindrome("alula")
True
>>> isPalindrome("love")
False
>>> isPalindrome(12)
False
>>> isPalindrome(12.21)
False
Also how can i adjust this code so i can input is_palindrome(something), instead of manually entering "something"