This is code of Phython >chapter 6 Loop> lesson Practice make perfect >topic censor
I m using code
def censor(text, word):
s=“”
c=len(word)
tex=text.split()
for x in tex:
if x==word:
s=s+" “+(”*" * c)
else:
s= s +" " + word
new=s[1:]
return new
It should work according to me but it show error
Error :-
**Oops, try again. Your function fails on censor(“Yo go fro yo go”,“go”). It returns “go ** go go **” when it should return "Yo ** fro yo ".
I understand why this error come but look t this code
def censor(text, word):
count = len(word)
tear = text.split()
new = “”
for item in tear:
if item == word:
new = new +" " + (“*” * count)
else:
new = new + " " + item
sliced = new[1:]
return sliced
Link of above code (Censor-solved)
Here both code are same but it shown error in my code not in another code.