Censor


#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/censor-?action=resume

<In what way does your code behave incorrectly? Include ALL error messages.>
Your function fails on censor(“hey hey hey”,“hey”). It returns “hey hey hey” when it should return " *".
(“hey hey hey”,“hey”) is an automatic input taken by the program.

<What do you expect to happen instead?>
According to my expectations, output should be “*** *** ***” instead of " *".

```python

Replace this line with your code.

def censor(text, word):
  astr = " "
  if word in text:
    astr = "*" * 4
    text.replace(word, astr)
  return text
<do not remove the three backticks above>

I don't understand the output this program is expecting for the input ("hey hey hey","hey").

#2

.replace() is dull to use, it allows for a single line solution. Please try to write your own function, it will teach you must more.

here:

astr = " "

why isn’t the string empty, why would you want to have a leading space?

here:

astr = "*" * 4

how do you know if you need four asterisks? hey has a length of 3, not 4


#3

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