Python Forum
List creation and return in Function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List creation and return in Function
#1
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!
Reply


Messages In This Thread
List creation and return in Function - by leoahum - Mar-04-2019, 04:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,637 Jan-05-2024, 08:30 PM
Last Post: sgrey
  nested function return MHGhonaim 2 608 Oct-02-2023, 09:21 AM
Last Post: deanhystad
  return next item each time a function is executed User3000 19 2,277 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  function return boolean based on GPIO pin reading caslor 2 1,171 Feb-04-2023, 12:30 PM
Last Post: caslor
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,661 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Need to parse a list of boolean columns inside a list and return true values Python84 4 2,102 Jan-09-2022, 02:39 AM
Last Post: Python84
  return vs. print in nested function example Mark17 4 1,738 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  How to invoke a function with return statement in list comprehension? maiya 4 2,825 Jul-17-2021, 04:30 PM
Last Post: maiya
  Function - Return multiple values tester_V 10 4,439 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Get return value from a threaded function Reverend_Jim 3 17,036 Mar-12-2021, 03:44 AM
Last Post: Reverend_Jim

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020