Censor (Don't know why it does not work)


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#


Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "('hey hey hey', 'hey')" when it should return "*** *** ***".


Why won't this work?


def censor(text, word):
    for i in text:
        for j in word:
            if i == j:
                i = "*"
    return text, word
    
print censor("this hack is wack hack", "hack")


#2

looping over a string will give you each letter:

def censor(text, word):
    for i in text:
        print i

print censor("this hack is wack hack", "hack")

you need words from your string, maybe split into a list first?

no need to loop over word, you want to check if word equals words from your text string

i and j are your loop iterators, change made to them won't persist


#3

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