Hi im writing a program that returns whether an inputted number is prime or not, but Im kind of stuck...

``````import math
def listfactors(n): # defining the function
l = []
for i in range (1, int(math.sqrt(n))+1):
if float(n)/float(i) == int(float(n)/float(i)):
l.append(i)
l.append(n/i)
return l

print "prime"``````

Now thats what I have so far but its not working and I was wondering if anyone could help point out my mistake and help me fix the last 2 lines.
Thank you :)

If you want to determine if a number is prime or not, you should return True (if prime) or False (if not prime). Use the modulo operator to determine if the entered number is divisible by loop variable i.

``if not n%i:``

If the statement evaluates True, return False. If the loop continues until it finishes, return True because the number must be prime.

The name of your function implies you have a different purpose. A better description would be is_prime:

``````if is_prime(primeNum):
print "The number is prime."
else:
print "Nope."``````

Your last 2 lines would be modified thusly

``````primeNum = int(raw_input("Enter number here:"))
A nit on operators: when you want integer-style division, discarding any remainder, the proper operator is `//` not `/` . As in: `l.append(n//i)` . In this particular case you already know the results are exact so no harm done, but it's good programming practice since it makes your intentions clear.