0
Can anyone explain Count Primes step by step ?
What I wanna know is the for loop part , X=3 check y in range (3,x,2) So y is 3 right ? then 3%3 == 0 X+=2 -> 5 break So 3 is not appended to the list right ? https://code.sololearn.com/cc3DL3dUTJ69/?ref=app
1 Antwort
0
a prime number is not divisible by any number rather than it self or by 1.
Example: 1, 11,19 ect.
so what you need is to set a condition: if num%2!=0 and num%3!=0
PS: number 2 is considered prime number coz they its only divisible by 1 and by it self.
#working example
def count_prime(nums):
c = []
for num in range(0,nums+1):
if nums == 0: # avoid ZeroDivisionError
continue
if num % 2 != 0 and num % 3 != 0:
c.append(num)
return c
print(count_prime(100))