10. censor error even expected output is printed


#1



when click save and submit button i get an error
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "*** *** " when it should return " *** ***".
as it sees both expected and returned result are same but i get errorr


def censor(text,words):
	lower_cased_text = text
	if(lower_cased_text.find("!") != -1):
		print "no punctuation are allowed"


	list_of_text = lower_cased_text.split()
	i =0
	astr = ""
	for word in list_of_text:
		print i
		if(word == words):
			list_of_text[i] = " "+"*" * len(words)+" "
		i +=1
	return "".join(list_of_text)[1:-1]


#2

i got the result when i changed the code like below

def censor(text,words):
lower_cased_text = text
if(lower_cased_text.find("!") != -1):
print "no punctuation are allowed"

list_of_text = lower_cased_text.split()
newlist = []
i =0
astr = ""
for word in list_of_text:
	if(word == words):
		print word
		newlist.append("*" * len(words))
		newlist.append(" ")
	else:
	    newlist.append(word)
	    newlist.append(" ")
return "".join(newlist)[:-1]

#3

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