Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

def censor(text, word):

L = []
a = ''
ast = '*' * len(word)
for index, c in enumerate(text):
if c != ' ':
a += c
if c == ' ' or index == len(text) - 1:
L.append(a)
a = ''
for index, item in enumerate(L):
if item == word:
L[index] = ast
output = ''
for index, item in enumerate(L):
if index != (len(L)-1):
output += item + ' '
else:
output += item
return output

b = input('Input a phrase : ')


censorword = input('What word to censor? ')
print(censor(b, censorword))

You might also like