1
phrase = str(input("Type your phrase: ")).upper().strip()
words_phrase = phrase.split()
words_together = ''.join(words_phrase)
phrase_inverse = ""
for letra in range(len(words_together) - 1, -1, -1):
phrase_inverse = words_together[letra]
print(phrase_inverse)
if words_together == phrase_inverse:
print("Esta frase é um palíndromo")
else:
print("Não é um palíndromo")
This program had the purpose of making a sentence look the other way, but when I run the code and the program tries to show the sentence backwards it only returns the first letter, and the phrase_inverse is inside the loop, it would be easier to leave:
phrase_inverse = words_together[letra:]
But exercise doesn’t allow.