210k views
1 vote
Write a program to detect if a word or phrase is a palindrome. The program should: 1. prompt the user to enter a word or phrase 2. determine if the word or phrase is a palindrome 3. let the user know if their entry is or isn't a palindrome 4. continue asking the user for a word or phrase to check, until they provide an empty string (just hit at prompt)

User Ali Alp
by
3.6k points

1 Answer

3 votes

Answer:

while True:

s = input("Enter a word: ")

if s != "":

reversed_s = ''.join(reversed(s))

if s == reversed_s:

print(s + " is a palindrome")

else:

print(s + " is not a palindrome")

else:

break

Step-by-step explanation:

- Initialize a while loop that iterates until the user enters an empty string

- Ask the user to enter a word

- If the word is not empty, reverse the word

- Check if reversed word is same as the original word. If they are same, then the word is a palindrome. If they are not same, then the word is not a palindrome.

User Frederik Heyninck
by
4.2k points