So I'm trying to learn Python using some tutorials, and I decided to create my own exercise. I wanted to create a script that figures out how many prime numbers there are between 1 and 1000, as well as printing the prime numbers. This is what I have so far:
numberlist = []
a = 1
prime = True
while a < 1000:
a = a + 1
for divisor in range(2,a):
if a/divisor==int(a/divisor):
prime=False
if prime == True:
print a
numberlist.append(a)
print "Number of prime numbers between 1 and 1000:", len(numberlist)
However, when I start the application, it returns
"Number of prime numbers between 1 and 1000: 0"
I don't know what I've done wrong. Can someone please clarify what I screwed up on?
Thank you for your help.
Edit: So now the code looks like this, but the same problem is occurring:
numberlist = []
a = 1
for a in xrange(1, 1000):
for divisor in range(2,a):
if a % divisor == 0:
prime=False
else:
prime=True
if prime == True:
print a
numberlist.append(a)
print "Number of prime numbers between 1 and 1000:", len(numberlist)
for divisor in numberlist(if you makeastart at 2, or dofor divisor in numberlist[1:]and just start withnumberlist=[1]).