tawfiqh
April 9th, 2009, 11:15 AM
i couldn't get my code for project euler problem 3 to work:
so i got this code for finding a prime in python:
num = input('Enter the number which you wish to determine it is prime: ')
if num < 2:
print "\nThe Number", num, " is not a prime!"
else:
for div in range(2, (num/2)+1):
if num%div==0:
print "\nThe Number", num, " is not a prime!"
break
else:
print "\nThe Number", num, " is a prime!"
I incorporated it into my program but it doesn't work
y=24
x=1
f=[]
pf=[]
while x<=y:
if y%x==0:
f.append(x)
if x < 2:
print "\nThe Number", x, " is not a prime!"
elif x>2:
for div in range(2, (x/2)+1):
if x%div==0:
break
else:
pf.append(x)
x=x+1
print f
print pf
it just ouputs:
The Number 1 is not a prime!
[1, 2, 3, 4, 6, 8, 12, 24]
[]
why doesn't it work?
so i got this code for finding a prime in python:
num = input('Enter the number which you wish to determine it is prime: ')
if num < 2:
print "\nThe Number", num, " is not a prime!"
else:
for div in range(2, (num/2)+1):
if num%div==0:
print "\nThe Number", num, " is not a prime!"
break
else:
print "\nThe Number", num, " is a prime!"
I incorporated it into my program but it doesn't work
y=24
x=1
f=[]
pf=[]
while x<=y:
if y%x==0:
f.append(x)
if x < 2:
print "\nThe Number", x, " is not a prime!"
elif x>2:
for div in range(2, (x/2)+1):
if x%div==0:
break
else:
pf.append(x)
x=x+1
print f
print pf
it just ouputs:
The Number 1 is not a prime!
[1, 2, 3, 4, 6, 8, 12, 24]
[]
why doesn't it work?