Python Forum
List creation and return in Function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: List creation and return in Function (/thread-16541.html)



List creation and return in Function - leoahum - Mar-04-2019

def factors(x):
   L = []
   for i in range(1, x + 1):
       if x % i == 0:
            L.append(i)
    return L


num = 84


print (factors(num))
I'm trying to return a list in this function. Python gives me an error "IndentationError: unindent does not match any outer indentation level"

Could someone help me fix it? Many thanks in advance!


RE: List creation and return in Function - Olivier - Mar-04-2019

Line 6 is not properly indented.


RE: List creation and return in Function - stranac - Mar-04-2019

Your indentation is all over the place.
At lines 2 and 3, it starts with 3 spaces, and then continues with 7, 12, and 4.


RE: List creation and return in Function - leoahum - Mar-04-2019

Thank you every one!