Ask Question
15 June, 08:51

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)

+4
Answers (1)
  1. 15 June, 11:19
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers