I am trying to output numbers that have only 3 factors. I wrote a code to output all the factors, but can't get it to output the number that has 3 factors. For instance, if a list has 1,5,6,7 .. it Will output 6 .. since 6 has three factors : 1, 2 and 3 .. (itself) not being a factor. This is what I have till now:
def factors(n):
result = []
for i in range(1, n + 1):
if n % i == 0:
result.append(i)
return result