def palindrome(number): palindrome = True numString = str(number) #converts into string numList = list(numString) #converts into list so the reverse function can be used numRev = numList.reverse() if(numList == numList[len(numList)-1]): #Checks to see if the first digit is the same as the last for i in range(1, len(numList)- 2): #Checks the inside digits to see if they match up if (numList[i] != numRev[i]): palindrome = False #if one of them doesn't, it's not a palindrome break else: #If the first and last digits aren't the same, it isn't a palindrome palindrome = False return palindrome #Returns 'True' or 'False' value..
I think my function is logically correct (If not, tell me!). It works perfectly with 3 digit numbers, but when I try to use numbers any longer than that, it gives me the following error message:
File "<pyshell#26>", line 9, in palindrome if (numList[i] != numRev[i]): TypeError: 'NoneType' object is not subscriptable
I've looked up what this error message means, but..I don't understand what I need to do to fix it. Help?
Also, I'm fairly new to this stuff, so don't judge my silly questions!