Write a Python program that reads in a string and determines whether the string is a palindrome or not. note that a sentence that reads the same forwards and backwards by resequencing the spaces is also a palindrome and your program should consider this.
sample run
enter string: mom
output: mom is a polindrame
enter string: a nut for a jar of tuna
output: a nut for a jar of tuna is a palindrome
string = input("enter string: ") s = string.lower() s = s.replace(" ", "") low = 0 high = len(s) - 1 result = True while(low<high): if(s[low]!=s[high]): result = False low+=1 high-=1 if result: print(string, "is a palindrome") else: print(string, "is not a palindrome")
Get Answers For Free
Most questions answered within 1 hours.