Ask Question
7 July, 13:20

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. 7 July, 16:40
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers