I am a newbie python coder learning for fun. I am wondering why this program has difficulty outputting the correct output. I believe the problem lies with the very end of the program "if list == inverselist:". I always get an output telling me the word is a palindrome even when it is not (e.g. tigers)
#Exercise 6 - Ask the user for a string and print out whether this string is a palindrome or not. (A palindrome is a string that reads the same forwards and backwards.)
possiblepalindrome = str(input("Put in the possible palindromic statement here: "))
print(possiblepalindrome)
list=[]
for x in possiblepalindrome: #put each individual string character in a new list as its own element
list.append(x)
print ('this is list', list)
for x in list: #Removes all spaces so multiple word/sentences can be palindrome
if x is ' ':
list.remove(' ')
print('this is with removed spaces' , list)
def reverselist(argument): #This is a function. We put in some list, then the list is reversed, and is spat back out
argument.reverse()
return argument
inverselist = reverselist(list) #We use the reverselist function to make an inverse list of the palindrome
print('this is inverselist',inverselist)
if list == inverselist:
print('Congratulations ', '"', possiblepalindrome, '"', ' is a palindrome!')
else:
print('Unfortunately', '"', possiblepalindrome, '"', 'is not a palindrome.')