I am working with a Palindrome-detector that is built using for-loops (this was a requirement for the course I am attending).
I am almost fully done with it but I am having trouble returning an argument and using it in the final function. The code looks like this:
#-*- coding: utf-8 -*-
def main():
intro()
text = (input("Inser text here: "))
ordnaText(text)
testPalindrom(ordnaText(text))
showResult(testPalindrom)
def intro():
print ("Hej! Detta är ett program som testar ifall en text är ett palindrom eller inte.")
def ordnaText (text):
nytext = ("")
fixedText = text.lower()
for i in fixedText:
if i.isalnum():
nytext = (nytext + i)
return nytext
def testPalindrome(nytext):
palindrome = True
for i in range (0, len(nytext)):
if (nytext[i]) != (nytext[len(nytext)-i-1]):
palindrome = False
return palindrome
def showResult(palindrome):
if palindrome == True:
print ("Yes, this is a palindrome")
else:
print ("No, this is not a palindrome.)
main()
Everything works except the final part: if I put in "lol" which is a palindrome it says that it's false. "palindrome" somehow doesn't return correctly. What am I doing wrong?