So i was looking around on here and i found the code for a working palindrome
def isPalindrome(): string = input('Enter a string: ') string1 = string[::-1] if string[0] == string[(len(string)-1)] and string[1:(len(string)-2)] == string1[1:(len(string)-2)]: print('It is a palindrome') else: print('It is not a palindrome') isPalindrome() So i already changed input to raw_input. And it works.
But in the comments there was a simpler code:
def isPalindrome(): string1 = input('Enter a string: ') string2 = string[::-1] if string1 == string2: return 'It is a palindrome' return 'It is not a palindrome' isPalindrome() I got the read back:
Traceback (most recent call last): File "C:\Python27\idk1.py", line 8, in <module> isPalindrome() File "C:\Python27\idk1.py", line 2, in isPalindrome string1 = input('Enter a string: ') File "<string>", line 1, in <module> NameError: name 'racecar' is not defined So i changed it to raw_input, and I wouldn't work at all. I'm curious as to why that is?
racecar?racecar" into a Python 2inputprompt.