Created
August 6, 2018 20:56
-
-
Save solen003/6ecf32b45ad541609a72d1edc0b77551 to your computer and use it in GitHub Desktop.
prime counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_primes(n): | |
import math | |
primes_count = 0 | |
for i in range(1, n+1, 2): | |
if i == 1: | |
pass | |
if i == 2: | |
primes_count += 1 | |
elif i%2 == 0: | |
continue | |
else: | |
for x in range(3, int(i**0.5)+1, 2): | |
if i%x == 0: | |
break | |
else: | |
primes_count += 1 | |
print(primes_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment