15/10 censor python


#1



merci de votre aide

https://www.codecademy.com/fr/courses/python-intermediate-fr-FR-py0yl/1/4?curriculum_id=5370f030fed2a866a2000001

Oups, merci de réessayer. Votre fonction a échoué sur ('Yo go fro yo go', 'go') comme entrée car votre fonction indique une erreur "'str' object is not callable".

pourtant le resultat est OK?
['Yo ', ' fro yo ', '']
Yo ** fro yo **
None

Replace this line with your code. 
def censurer(texte, mot): 
    texte_split = texte.split(mot)
    print texte_split
    etoiles = "*" * len(mot)
    return ("*"*len(mot)).join(texte.split(mot))

print censurer('Yo go fro yo go','go')


#2

Salut bon voila ce que j'ai mis moi, a la fin il faut ajouté une ligne pour contourner le bug de traduction de codecademy voila :slight_smile:

def censurer(texte, mot):
    txts = ""
    for x in texte.split():
        if x == mot:
            s = "*" * len(mot)
            txts += s+" "
        else:
            txts += x+" "
    return txts

print censurer("ttt yyy uuu", "yyy")

Exception = "somebody should fix this bug..."

#3

It is difficult to handle the " ". But if you insist on dong it that way, the code below may help you. FORGIVE MY POORLY HTML-_-

    def censurer(texte, mot):
    txts = ""
    for x in texte.split():
        if x == mot:
            s = "*" * len(mot)
            if len(txts) != 0:
                txts += " " + s
            else:
                txts += s
        else:
            if len(txts) != 0:
                txts += " " + x
            else:
                txts += x
    return txts

#4

thanks this use an else/for I think that is why it showing me error ! # great day


#5

I have done it by myself! It takes me so much time, crying~~~


def censor(text, word):
text1 = []
word1 = []
for a in text:
text1.append(a)
for b in word:
word1.append(b)
for i in range(len(text1) - len(word1) + 1):
if text1[i:(i + len(word1))] == word1:
text1[i:i + len(word1)] = "*" * len(word1)
text = "".join(text1)
return text
print "this hack is wack hack"
print censor("this hack is wack hack", "hack")


#6

def censor(text, word):
d = text.split(" ")
a = len(d)
b = len(word)
c = ""
for n in range(0, a):
if d[n] == word:
d[n] = "*" * b
c = " ".join(d)
return c