Honestly I have no idea what I am doing right now


#1


10.Censor

This is what I have and I am not surprise it doesn't work, I just feel compeletly dumbfounded I have no idea how to solve this one.


def censor(text, word):
    a = text.split()
    b = len(word)
    cens= ""
    for n in a:
        if n != word:
            cens += n
        else:
            cens += "*" * b
        return cens
print censor("Come here rude boy","boy")#would you give it up


10.censor
#2

the if command should be while


#3

Huh? I don't see how that would correct anything. What is missing is the space separator in the returned string.

If cens is a list, it can be joined in the return statement.


#4

So if I make cens a list what should I do next?


#5

This line will become,

cens.append(n)

and the other, similarily.


#7

def censor(text, word):
a = text.split()
b = "*" * len(word)
cens=[]
for n in a:
if n == word:
cens.append(b)
else:
cens.append(n)
return cens
result="".join(cens)
print result

print censor("Come here rude boy","boy")

why doesnt /// result = "".join(cens) /// work?


#8

Because it is after a return. Instead of setting result, just return that value.


#9


Also tried instead of "for wor in cens" I did result="".join(cens) but that didn't work either

Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "['', '', '']" when it should return " *** ***".


def censor(text, word):
    a = text.split()
    b = "*" * len(word)
    cens=[]
    total = ""
    for n in a:
        if n == word:
            cens.append(b)
        else:
            cens.append(n)
    return cens
    
    for wor in cens:
        total = total + wor
    return total
    print total
    
        
    

print censor("Come here rude boy","boy")#would you give it up


#11

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