so I am attempting to write a function that returns factors of a given number. when I use the print function my code give the correct output when I use the return function it outputs 1 for ever input.
Here is my code:
def getFactors(x):
"""Returns a list of factors of the given number x.
Basically, finds the numbers between 1 and the given integer that divide the number evenly.
For example:
- If we call getFactors(2), we'll get [1, 2] in return
- If we call getFactors(12), we'll get [1, 2, 3, 4, 6, 12] in return
"""
# your code here
for i in range(1 , x + 1):
if x % i == 0:
return(i)
x = int(input("please enter and integer: "))
getFactors(x)