Created
July 14, 2019 21:39
-
-
Save adityasuseno/9a3e1a3bf7c1373710f800a007c19028 to your computer and use it in GitHub Desktop.
Simple program to count prime number
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
#!/usr/bin/env python3 | |
def isPrime(n): | |
# if n < 2: | |
# return False | |
# elif n == 2: | |
# return True | |
# else: | |
for i in range(2, n): | |
p = n % i | |
if p == 0: | |
return False | |
break | |
return True | |
while True: | |
try: | |
r = int(input('Tampilkan Banyaknya Bilangan Prima antara 1 ~ ')) | |
break | |
except ValueError: | |
print('Please Enter Number Only!') | |
y = 0 | |
for x in range(2, r + 1): | |
if isPrime(x) == True: | |
y += 1 | |
print(y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment