I am currently struggling with a homework problem and I need some help, as I feel like I'm a bit confused. I work on creating a program that looks for palindromes within integers only. The program I've made I know will accurately identify palindromes within integers, but I cannot get the program to identify when the input is not an integer (float, bool, str, etc.). I specifically want the program to note when an integer is not the input and print "The input is not an integer" before breaking. Here is my code below:
def Palindrome(n):
return n == n[::-1]
n = input("Please enter an integer: ")
ans = Palindrome(n)
if ans == True:
print("The number " + n + " is a palindrome")
elif ans == False:
print("The number " + n + " is NOT a palindrome")
I know this is kind of basic, but everyone needs to start somewhere! If anyone could explain what I could do to create the program and understand how it works, it would be very appreciated :)