<In what way does your code behave incorrectly? Include ALL error messages.>

Your function fails on censor(“Yo go fro yo go”,“go”). It returns "yo fro yo " when it should return "Yo fro yo ".

<What do you expect to happen instead?>

I put extra print statements in my code just so I could understand what is being inputted and the results. My console output is this-

the password is spam
the password is ****
hey hey hey

Yo go fro yo go
yo ** fro yo **

Which I think is the right solution? Then why is it showing me an error?

def censor(text, word):
  print text
  print word
  #Make the text and word lowercase
  #Splitting the string into words
  word_arr=text.split(" ")
  #checking if the word exists in the array and replacing it if it does
  for index in range(len(word_arr)):
    if word==word_arr[index]:
      #genenrating censored word
      for number in range(len(word)):
  print " ".join(word_arr)  
  return " ".join(word_arr)


the error is caused by the fact that you use .lower(), we should just leave the input as it is. Its also what is causing the error

the first word of Yo go fro yo go is uppercase, so the exercise Yo to be returned. Converting to lowercase will cause a problem


Thank you so much! I feel like a complete moron though, serves me right for not reading the error message properly, gah!


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