What is wrong, it says "*** *** ***" is not the same as "*** *** ***"?


#1


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

The error shows that censor("hey hey hey", "hey") should return "*** *** " and not " *** ***". I am so confused.
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "*** *** " when it should return " *** ***".
(Note: all the prints are for debugging)


def censor(text, word):
    print text
    final = ""
    length = len(word)
    insert = ""
    for i in range(length):
        insert += "*"
    print insert
    if text[0 : length] == word:
        final = insert + " "
        text = text[length : len(text)]
    space = False
    subWord = ""
    text += " "
    for i in range(len(text)):
        if text[i] == " ":
            space = False
            print subWord
            if subWord == word:
                subWord = insert
            final += subWord + " "
            subWord = ""
        else:
            subWord += text[i]
    final = final[0 : len(final) - 1]
    return final
    
print censor(""hello world this world is a great world with many things to do in this world", "world")


#2

Oops, i forgot to remove the space variable. It doesn't change anything but it was from something i was trying earlier.


#3

i may have added a extra quotation when changing the phrase but when removed, it still doesnt work!!!!!!!!!!!!!!!!!!!!


#4

For censor("hey hey hey", "hey") your function returns:

'***  *** ***'

but the correct answer is:

'*** *** ***'

Do you see the difference now?


#5

Thx, i just figued it out a few minutes ago and fixed it


#6

You're welcome :panda_face:


#7

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