Ask Question

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)

+2
Answers (1)
  1. 1 April, 02:33
    0
    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

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers