Why this is not working phython (practice make perfect) censor


#1

This is code of Phython >chapter 6 Loop> lesson Practice make perfect >topic censor
I m using code

def censor(text, word):
s=""
c=len(word)
tex=text.split()
for x in tex:
if x==word:
s=s+" "+("*" * c)
else:
s= s +" " + word
new=s[1:]
return new

It should work according to me but it show error
Error :-

Oops, try again. Your function fails on censor("Yo go fro yo go","go"). It returns "go ** go go **" when it should return "Yo ** fro yo **".

I understand why this error come but look t this code

def censor(text, word):
count = len(word)
tear = text.split()
new = ""
for item in tear:
if item == word:
new = new +" " + ("*" * count)
else:
new = new + " " + item
sliced = new[1:]
return sliced
Link of above code (https://discuss.codecademy.com/t/censor-solved/59435)

Here both code are same but it shown error in my code not in another code.


#2

Could you please give us the following information:

  • Current Programming Language > Chapter > Lesson
  • Instructions for the lesson.
  • Your current code for the lesson (See example 1)
  • The error you're receiving for the lesson.

Currently it is impossible to assist you as we have no way of determining what lesson you're on or why your code is failing. The format of your post can be considered SPAM, and it would be best in the future to write with the reader in mind.

example 1)

var variable = "example";

Thanks in advance!

~lolman


#3

phython (practice make perfect) censor


#4

Once again I can't assist you. Unless you can provide the information cited in my last comment then we are unable to help.


#5

Look the post now i edited as you said