[Python] Why my code palindrome works only for single input not for many inputs?

Discussão em 'Python' iniciado por Stack, Fevereiro 7, 2025.

  1. Stack

    Stack Membro Participativo

    A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome.

    I'm only getting this half right. my code is working for bob, and sees. When an input is "never odd or even" my code doesn't work it shows is not a palindrome but it should be a palindrome.

    What am I doing wrong here?

    word = str(input())
    new = word.replace(" ", "")
    new = new[::-1]

    if word == new:
    print('{} is a palindrome'.format(word))
    else:
    print('{} is not a palindrome'.format(word))

    Continue reading...

Compartilhe esta Página