Dans cet exercice, nous allons vérifier si une phrase est un palindrome ou non.
Un palindrome est un mot ou une phrase qui peut se lire de la même façon dans les deux sens.
Dans cet exemple-ci, nous avons le palindrome "Un rocu cornu"
.
Votre script devra donc vérifier si cette phrase est un palindrome, et donc dans ce cas-ci, retourner la valeur True
dans la variable resultat
.
mot = "Un roc cornu" formated_word = mot.replace(" ", "").lower() resultat = formated_word == formated_word[::-1]
Lionel

mot = "Un roc cornu" resultat = mot.replace(' ', '').lower() == mot.replace(' ', '').lower()[::-1]
Puco

mot = "Un roc cornu" mot_no_space = "".join(mot.lower().split()) resultat = True if mot_no_space == "".join(reversed(mot_no_space)) else False
aanks

mot = "Un roc cornu" mot1 = mot.lower().replace(" ", "") mot2 = mot1[::-1] resultat = mot1 == mot2
frkb

mot = "Un roc cornu" def palindrome(mot): mot = "".join(mot.lower().split(" ")) if mot == mot[::-1]: return True resultat = palindrome(mot)
mot = "Un roc cornu" resultat = mot.lower().replace(" ", "") == "".join(reversed(list(mot.lower().replace(" ", ""))))
Romu80

mot = "Un roc cornu" mot = mot.lower().replace(" ", "") resultat = list(mot) == list(reversed(mot))
Raphaël

def palindrome(mot): mot_formate = mot.replace(" ", "").lower() mot_inverse = mot_formate[::-1] if mot_formate == mot_inverse: return True return False mot = "Un roc cornu" resultat = palindrome(mot)
Gabriel Trouvé

mot = "Un roc cornu" mot_lower = mot.replace(' ','').lower() resultat = mot_lower == mot_lower[::-1]
mot = "Un roc cornu" mot = mot.lower().replace(" ","") if mot == mot[::-1]: resultat = True else: resultat = False
TheCrow

mot = "Un roc cornu" space = " " mot = "".join(i for i in mot if i not in space) mot = mot.lower() palindrome = "".join(reversed(mot)) if mot == palindrome: resultat = True else: resultat = False print(resultat)
Nelson

mot = "Un roc cornu" resultat = (True if mot.lower().replace(" ", "")[::-1] == mot.lower().replace(" ", "") else False)
Salvatore

mot = "Un roc cornu" resultat = True if mot.replace(" ","").lower() == ''.join(reversed(mot.replace(" ","").lower())) else False
mot = "Un roc cornu" def ispalindrome(chaine:str): tampon = chaine.split(" ") tampon = "".join(tampon) if list(reversed(tampon.lower())) == list(tampon.lower()): return True return False print(ispalindrome(mot))
Brieux

mot = "Un roc cornu"
Un instant...
Test de la variable resultat
La variable resultat
doit contenir le booléen True
car la phrase à tester est dans ce cas-ci bien un palindrome.
Bravo, tu as réussi cet exercice de code 🥳

Soumettre ma solution
Vous avez trouvé une solution alternative pour cet exercice ? Proposez votre solution à la communauté 👇
Seules les propositions différentes de la solution proposée par Docstring peuvent être envoyées.
Ma solution :
Mes notes
Sauvegardé