# File: ChapterStrings/palindrome.py """ Checks if a word is a palindrome: is the same with its reverse. Ex: eye Enter a word? racecar racecar Is a palindrome! """ def main(): while True: s = input("\nEnter a word (quit-q)? ") if (s == 'q'): break printrev(s) #just prints in reverse srev = reverse(s) if ( s == srev ): print("Is a palindrome!") else: print("Not palindrome") myrev(s) def reverse(ss): res = "" # result has to be initalized to empty string for c in ss: # add letter at the beginning res = c + res return res def printrev(ss): #just prints in revers does not build anything n = len(ss) for i in range(n): # n-1 is the last index! print(ss[n-i-1],end="") print() def myrev(ss): # same reverse written in another way print("\nPrint in reverse string ", ss) for i in range(len(ss)-1,-1,-1): print(ss[i],end="") main()