10/15 code won't work


#1
def censor(text,word):
  star = "*"*len(word)
  words = text.split()
  for i in range(len(words)):
    if words[i] == word:
      words[i]=star
  else:
    print " ".join(words)

Why my code doesn’t work for that? I tested with some examples and it worked fine, but the system won’t accept it


#2

read the instructions careful, you need to return the censored sentence


#3

Thanks!
I just tested also for (“hey hey hey!”,“hey”), and it will return “*** *** hey!”…
=(
I will try another way. Thank you for the quick response


#4

Can i see what you did? Your solution seems correct for the rest


#5
def censor(text,word):
  star = "*"*len(word)
  words = text.split()
  for i in range(len(words)):
    if words[i] == word:
      words[i]=star
  else:
    result = " ".join(words)
    return result
print censor("hey hey hey!","hey")

#6

the last hey! has an exclamation mark, so hey! won’t equal hey (the word we want to censor)

This program is not yet designed to handle punctuation marks. Its an additional challenge, but not one which is in the scope of the exercise


#7

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