ERROR: Practice Makes Perfect, Censor


#1




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


I wrote code that fulfills the need of the lesson, but the lesson insists my function fails for "hey hey hey." When I test that variable, my code correctly replaces it with "*** *** ***." I am very new to Python, so please thoroughly explain where am I going wrong? Since I am new, I welcome all advice to become a better programmer.


text=raw_input('Enter phrase: ')
word=raw_input('Find and replace which word with an asterisks?')
def censor(text, word):
    text_separated=text.split()
    for count, x in enumerate(text_separated):
        if x==word:
            text_separated[count]='*'*len(x)
    print " ".join(text_separated)
print censor(text, word)


#2

you print the censored string, you should return it


#3

When I return, I get another error:

"maximum recursion depth exceeded while calling a Python object"

I don't understand. When I print the function, it works correctly. When I return, I have other errors.


#4

post a version of your code with return


#5

text=raw_input('Enter phrase: ')
word=raw_input('Find and replace which word with an asterisks?')
def censor(text, word):
    text_seperated=text.split()
    for count, x in enumerate(text_seperated):
        if x==word:
            text_seperated[count]='*'*len(x)
    print " ".join(text_seperated)
    return censor(text, word)

#6

here:

print " ".join(text_separated)

you print the censored string, you should return it.


#7

Thank you for showing me how to indent my code!!!


#8