Whats wrong with my code. 10.censor


#1

"""Write a function called censor that takes two strings, text and word, as input. It should return the text with the word you chose replaced with asterisks.

For example:

censor("this hack is wack hack", "hack")
should return

"this **** is wack ****"
Assume your input strings won't contain punctuation or upper case letters.
The number of asterisks you put should correspond to the number of letters in the censored word."""

my code

def censor(text,word):
new_text= ""
a= text.split()
c=len(word)
for i in a:
if i != str(word) :
new_text += str(i) + " "
if i == str(word) :
new_text += ''c + " "
return new_text


#2

The extra (trailing) space is the issue. Try building a list instead of a string, then join the return value to send back string with no trailing spaces.


#3

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