I do not understand why this code (python) does not create prime numbers from 1 to 20.
P = [2, 3]
p = 4
N = list(range(2, p))
M = list(range(1, p))
while True:
for n in N:
if p / n in M:
p += 1
if p == 20:
print(P)
break
else:
P.append(p)
p += 1
if p == 20:
print(P)
break
The idea was to start with 4 and check if the division between the number and the other (smaller) number of holes, if any, put it on the list and print the list at the end.
instead of printing printed strokes. [2, 3, 5, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
I know this is a very unforgivable way to find prime numbers, but I still don't understand why this is not working.
Thanks and sorry for my english.
source
share