10. Censor - Error


#1


https://www.codecademy.com/es/courses/python-intermediate-en-e9z06/1/4?curriculum_id=53a32847fed2a88075000001#

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)
    mem=False
    contador=0
    for i in range(len(testo)):
        if testo[i]==pallabra[0]:
            mem = True
            contador=0
            while mem is True and contador<len(pallabra):
                for j in range(len(pallabra)):
                    if testo[i+j]!=pallabra[j]:
                        mem = False
                    else:
                        contador+=1
            else:
                if contador==len(pallabra):
                    for j in range (len(pallabra)):
                        testo[i+j]="*"
    return testo


#2

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(termino)
        else:
            resultado.append("*" * len(palabra))
    return " ".join(resultado)

#3

Gracias por tu rápida respuesta, Roy!

Thank you for your quickly answer Roy!

Disculpa las molestias


#4

Not at all.

Happy coding!


#5

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