10. Censor


#1



I've tried a lot of things and still can't make this work. The console says I can't assingn to function call. What does that mean? How can I make it work?


Here's the lesson:
https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4#


Here's what the console says:
File "python", line 10
SyntaxError: can't assign to function call


Here's my code

text = raw_input("Input the sentence: ")
word = raw_input("Input the word you would like to censor: ")
censored = ""
def censor(text, word):
    text_splited = text.split(" ")
    censor = ["*" * len(word)]
    print text
    for words in range(len(text_splited)):
        if text_splited(words) == word:
            text_splited(words) = censor
        else:
            continue
censor(text, word)


#2

This code:

text_splited(words)

looks like a function call. But text_splited is just a normal variable, why you want to pass parameters to it?


#3

Isn't text_splited where the words from the text the user inputed are saved in? I'm trying to take the word that's equal to the one saved in 'word' and censor it


#4

words is a numerical value, an index. If you want to retrieve element of text_splited at index words you have to use this code:

text_splited[words]

#5

Ok, I managed to censor it, but I still can't return the whole text with the censored parts


#6

You have to return elements of the text_splited separated by a single space and joined into the string... perfect use case for join method :slight_smile:

return ' '.join(text_splited)

#7

I've been trying to do that but it the console says it was expecting a string or unicode but found a list. What am I doing wrong


#8

Problem is in this line:

censor = ["*" * len(word)]

Print text_splited before return to get a better understanding of the problem.


#9

Sorry, I still don't get it


#10

Wait, I think I got it


#11

Why the second element of the printed list (['**']) is... a list?


#12

I got it, thank you for taking your to time to help me


#13

You're very welcome :slight_smile:


#14

Now an unrelated question: is this forum just Code Academy Python lessons related or is about Python in general?


#15

This section is meant for the questions related to the exercises.

But please feel free to post everything that is not related to exercises in the corner bar section of this forum -> https://discuss.codecademy.com/c/Codecademy-Community-Lounge/Corner-Bar. You can even ask for help in your personal projects.


#16

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