Practice makes perfect 10/15: why isn't this code registering as correct?

I’m working through the “Practice Makes Perfect” section of the Python course and I’m on 10/15.

I’ve written this code and it seems to output the correct response, but it won’t register as correct. Can someone help?

def censor(text,word):
  nt = text.split()
  nl = ""
  nw = "*" * len(word)  
  for char in nt:
    if word == char:
      nl = nl + " " + nw
    elif word != char:
      nl = nl + " " + char
  return nl
print censor("hey what's up hey", "hey")

You having a leading space, lets replace the spaces with underscores so we can visualize the problem:

1 Like