In [2]:
j = 0 # add check counter outside the for-loop so it doesn't get reset
for num in range(1,101):
prime = True
for i in range(2,num):
if (num%i==0):
prime = False
if prime:
if j%2 == 0: # test the check counter for being even and if so, then print the number
print num
j += 1 # increment the check counter each time a prime is found
In [12]:
j = 0
for num in range(1,101):
prime = True
for i in range(2,num):
if (num%i==0):
prime = False
continue
# once the number has already been shown to be false,
# there's no reason to keep checking
if prime:
if j%2 == 0:
print num
j += 1
In [12]:
In [ ]: