I have to find the amount of prime numbers within a certain range in Python, and I have to use a for ... in range loop. I have been struggling with this so much these past few days and it has just been getting absolutely tiring. I have an idea how to do this, but when I put it into code, it just never works properly, no matter how hard I try. Anyways, here is my code:
def num_of_primes(n):
count = 1
primeNum = 0
for count in range(2, n+1):
if (n % count == 0 and count == n and (n % count != 0 and count != n)):
primeNum += 1
return primeNum
I think I know why this doesn't work, but I have no idea how to fix it so that it works properly. Oh and also, I have to do this using only ONE function (forgot to add that, sorry).