10/15


#1

Why does this return “‘int’ object is not iterable” and cut short?
def censor(text,word):
x="“
while len(x)+len(word) < range(len(text)):
print x
print text[len(x):len(x)+len(word)]
print word[:]
print len(x)
if len(word)+len(x)>len(text):
x+=text[len(x)]
continue
else:
if text[len(x):len(x)+len(word)]==word[:]:
for v in len(word):
x+=”*"
else:
x+=str(text[len(x)])
else:
x+=text[len(x)]
print text
print word
print x

i didnt know if x in y was a thing and went overboard i get it but now i just want to know why this doesnt work. thank you


#2

That says why though

read it and think about what it says, also consider the associated line number and compare to what that says
(and if you’re not getting a line number, call the function yourself so that the error shows up in the console, but then again, that message says what’s going on so it might not be very hard to spot where it’s happening with such short code)


#3

the program calls censor(“the password is spam”, “spam”) and it makes it all the way up to the last space just fine. clearly there’s no problem b4 then


#4

Space? In the text? The location to look for is the line in the code where it happens, not where in the input it’s processing at the time (though that might also be relevant, but it might also not be)

When python has to stop (crash), it says what goes wrong (‘int’ object is not iterable) and says where it stopped, so you’ve got a line number which tells you where to look, and you’ve already got the information of what’s going wrong, so you’d now look at the line and consider how it may be causing that

Again, though, by just reading what it says: ‘int’ object is not iterable, you can figure out where it is, because you’re not iterating in a whole lot of places and then just look for where you try to iterate through an int


#5

its not giving me the line. maybe its my browser.


#6

You might not be calling your function, it would therefore not reach that point and crash, so there would be no error to show (not until codecademy runs its own tests, but that won’t show you the full error message)


#7

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