Censor help plz


#1

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


Could someone tell me what is wrong with my indentation?
Thank you!



Replace this line with your code.


#2

In python, indentation is very important. Your return statement is meant to be inside of your censor function. Correct indentation:

def censor(text,word):
    newword="*"*len(word)
    for i in text.split()
        if i == word:
            censored.append(newword)
        else:
            return " ".join(censored)

PS: If there is still an error after indenting, make sure to look into if "censored" was already defined or not


#3

here is another way you can nailed this ...

def censor(text, word):
while word in text:
text=text.replace(word, len(word)'')

print 'Here is your new text', text
return (text)

text=raw_input('text:')
word=raw_input('word:')

censor(text, word)


#4

def censor(text, word):
text = text.split()
m = -1
for rijec in text:
m += 1
if rijec == word:
text[m] = "*" * len(word)
text = " ".join(text)
return text

print(censor("this hack is was hack", "hack"))

This maybe helpful~


#5

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