Please tell me what’s wrong with my code - Censor


#1
def censor(x, y):
  x= raw_input("Enter text:")
  y= raw_input("Enter word:")
  z="*" * len(y)
  new_string =''
  split_string = x.split()
  for c in range(len(split_string)):
    if split_string[c] ==y:
      split_string[c] = z
      new_string = " ".join(split_string)
  return new_string

Your function fails on censor(“hey hey hey”,“hey”). It returns “” when it should return " *".
Please tell me what’s wrong with my code


Censor
#2

It makes little sense to have a function take two parameters then overwrite them with user inputs inside the function. We are to write a simple utility that will work on any phrase and word arguments.

censor(“hey hey hey”,“hey”)

should return, "*** *** ***"


#3

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