10. Censor - Error



Hi! I'm trying to do this exercise. It's in spanish but only some few words and some of them are not even spanish words so I hope language isn't a barrier. The error is this:

"¡Uy! Probá otra vez. ¿Tu función de censura tiene exactamente dos argumentos? ¿una cadena de texto y una palabra para reemplazar con asteriscos?Tu codigo mostro el error "'str' object does not support item assignment"."

I couldn't prove my prototype so maybe is fill of mistakes but I can't run the program and this is the reason but I can't fix it or/and understand it.

Thank you for read me

P.S.: I don't understand very well how it is supposed to use the boolean form. An error appears when I put "mem=True" in the "while" and I don't know if "is" means is (verb to be) and, well, help will be welcome

def censor (texto, palabra):
    testo = str(texto)
    pallabra= str(palabra)
    for i in range(len(testo)):
        if testo[i]==pallabra[0]:
            mem = True
            while mem is True and contador<len(pallabra):
                for j in range(len(pallabra)):
                    if testo[i+j]!=pallabra[j]:
                        mem = False
                if contador==len(pallabra):
                    for j in range (len(pallabra)):
    return testo


I just did the lesson and passed with this. Give it a study and see if it helps simplify your program (which is pretty complicated).

Acabo de hacer la lección y pasar con esto. Darle un estudio y ver si ayuda a simplificar su programa (que es bastante complicado).

def censor(texto, palabra):
    palabras = texto.split(' ')
    resultado = []
    for termino in palabras:
        if termino != palabra:
            resultado.append("*" * len(palabra))
    return " ".join(resultado)


Gracias por tu rápida respuesta, Roy!

Thank you for your quickly answer Roy!

Disculpa las molestias


Not at all.

Happy coding!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.