is your return lined up with the for
Don’t mix indentation between spaces and tabs. Try to erase all of them and make 4 spaces or 1 tab indentation for each block.
I took the code from codecademy using “get code”, then i removed all the tabs and placed the following tabs:
def: 0 tabs
results: 1 tab
for numbers: 2 tabs
for number: 3 tabs
results.append: 4 tabs
return: 1 tab
This was my error report:
File “python”, line 6
for numbers in lists:
IndentationError: unexpected indent
Thanks in advance
is it a bug then?
(filling the minimum of 20 characters here)
Could you post the link to the exercise? Only if you haven’t solved it yet or keep getting the same issue.
i have solved it by hitting get code, but i did try again and got the same error. this is the url:
but i suppose it won’t refer to my code.
how can i copy and paste my code to this forum while keeping the indentation?
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]] # Add your function here def flatten(lists): results =  for numbers in lists: for number in numbers: results.append(number) return results print flatten(n)
You have a extra indentation at the first
for, therefore, you should remove it and the same for the next two lines.
Indentation is supposed to delimiter code blocks, not only for improve readability. In this case, the extra indentation at the first
for means you are putting everything as part of results code, but that’s not a sub-function for python to work properly.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.