@coderockstar13753 You are nearly there! All you need is:
def censor (text,word):
# additionally, `.index` gives error when `word`
# is not present in `text`, so use below condition
if word in text:
a = "*" * len(word)
b = text.index(word)
start = text[0: b] # string before the word
end = text[b+len(word): ]
c = start + a + end
return censor(c, word) # this line is all you need
print censor("hey hey hey", "hey")
I am giving you a dry run of the code to see how it works:
censor("hey hey hey", "hey")
-- word is in text; if-branch executed
-- c = "*** hey hey"
-- return censor("*** hey hey", "hey")
-- >- word is in text; if-branch executed
-- -- c = "*** *** hey"
-- -- return censor("*** *** hey", "hey")
-- -- >- word is in text; if-branch executed
-- -- -- c = "*** *** ***"
-- -- -- return censor("*** *** ***", "hey")
-- -- -- >- word is NOT in text; if-branch not executed
-- -- -- -- return "*** *** ***"
Read it carefully a few times. Experiment on the repl. If you are uncomfortable with this, I'll give you a while loop solution
And, @ignasiseguravicente, yes, you've indeed got a much easier solution, but as you'll see, we are debugging and helping @coderockstar13753 understand the closest alternative to his original solution that works well. While you have utilized an existing built-in method, we are discussing the possible implementation of that built-in method itself. Any way, kudos to you for having figured out the easier solution