Will someone please resolve the error in this code, result is same as wanted


#1

def censor(text,word):
    word2=[]
    s=""
    word2=text.split(" ")
    
    for i in word2:
         if i==word:
             for t in i:
                 s+="*"
             
         else:
             s+=i
          
         s+=" " 
    text=s 
    
    return text

#2

you have an additional space at the end of your sentence, this causes the error

you could string slicing to get rid of it


#3

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