I am currently working on a palindrome-detector (anna, lol, hahah etc) and I am requested to use for-loops.
I want the program to loop through two strings (read them regularly and backwards at the same time while comparing the values). If the values are the same then the palindrome is True; if not, it's False.
My question to you is: how do you get two for-loops to run simultaneously and compare the values of the strings?
Currently doing something like this: (Python 3.0), can post entire code if needed:
palindrom = True
text2 = ("")
for i in nytext:
for i in nytext[::-1]:
text2 = (nytext[::-1] + i)
if text2 == nytext:
palindrom = True
else:
palindrom = False
return palindrom
Thank you for your help!
EDIT: I might not have been clear enough when describing the problem. The program does this: It lets the user enter a string of text (such as hello my name is lol) and the program is designed to see if this is a palindrome. It is divided into three functions (and a main function).
Function number 1 fixes the text so it is reduced into characters and digits only (so LOL,,,,,, becomes lol for easier reading). Function number 2 is designed to test (using for-loops(!)) if the input is a palindrome. Function number 3 is simply going to post whether it is a palindrome or not.
I have to use for-loops for this and I cannot simply do a comparison such as: backwardtext = text.reverse() if backwardtext == text: print ("It is a palindrome")
I hope this clears things up.