Is there a question here?
You have an error message there, what is it telling you? What do you think it means, what have you tried to do about it?
Make sure that the code in your post is properly formatted so that others are able to test/run the code.
hey you need not not to write such a long code
check this out
garbled = “IXXX aXXmX aXXXnXoXXXXXtXhXeXXXXrX sXXXXeXcXXXrXeXt mXXeXsXXXsXaXXXXXXgXeX!XX”
message = filter(lambda x: x != “X”, garbled)
print message
They are wanting you to use lambda expressions instead of defining a function. This is my code maybe you can work backwards from it to see how I was thinking.
garbled = "IXXX aXXmX aXXXnXoXXXXXtXhXeXXXXrX sXXXXeXcXXXrXeXt mXXeXsXXXsXaXXXXXXgXeX!XX"
message = filter(lambda x: x is not "X", garbled)
print message
But to fix your function:
garbled = "IXXX aXindent preformatted text by 4 spacesXmX aXXXnXoXXXXXtXhXeXXXXrX sXXXXeXcXXXrXeXt mXXeXsXXXsXaXXXXXXgXeX!XX"
def remove_garbage(garbled):
message = ""
for char in garbled:
if char != 'X':
message += char
print message
return message
remove_garbage(garbled)
Your syntax was probably a bit off, your “return message” needed to be in line with your “for” loop. I also found that if you want to print to the console it’s better to print before returning or call for print when you call your function.
The letter ‘x’ means the element of the variable ‘grabled’, which in this context, its letters. When we iterate thru ‘x’ in ‘grabled’, if ‘x’ is not equal to ‘X’ OR x != “X” ( != is ‘not equal to’), then ‘x’ will be printed.
for loop must be aligned below the message ="",you know Python’s indentation rules,
so make changes from for loop on words
you can see my code here.so you can see the difference .hope it helpful