I am trying to print out all prime numbers that are in an array called 'checkMe'. But I just can't get it to work. I've succesfully made a program that checks it for one number but it doesn't work for an array. If anyone knows what is wrong on please tell me. BTW: I am a big noob in python so it probably isn't the most beautiful code.
checkMe = range(1, 100)
dividers = []
primes = []
for y in checkMe:
x = y
for x in range(2, x):
if (y/x).is_integer():
dividers.append(x)
if len(dividers) < 2:
primes.append(y)
print("\n"+str(checkMe)+" has "+str(len(primes))+" primes")
print(primes)
Output:
range(1, 100) has 5 primes
[1, 2, 3, 4, 5]
Expected Output:
range(1, 100) has 25 primes
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83,
89, 97]