Why this code doesnt work?


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096


The code prints ****** babybaby ***


It should print *** baby ***


Replace this line with your code. 

def censor(text,word):
    b=""
    c=""
    for a in text:
        if a!=" ":
            b+=a
        if a==" ":
            if b==word:
                c=c+"*"*len(word)
                c=c+" "
            else:
                c=c+b+" "
            b=""
        if a==text[len(text)-1]:
            if b==word:
                c=c+"*"*len(word)
            else:
                c=c+b
    return c
print censor("Hey baby Hey","Hey")


#2


type or paste code here
try this:

def censor(text, word):
text=text.split
word=[]
for i in word:
if i == word:
word.append("*" * len(word)
" ".join(word)
return " ".join(word)
censor("Its cock", "cock")


#3

i havent encountered split function in the course.Can u plz find the fault in my code?


#4

cant seem to find wats wrong but: read through the hint and u will see that u were ask to use split.


#5

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