Created
November 30, 2017 07:44
-
-
Save azdafirmansyah/6c610e89b2dc90d11c7399fec71c6091 to your computer and use it in GitHub Desktop.
Check Prime Number
This file contains hidden or 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
''' | |
Exercise URL : http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html | |
Ask the user for a number and determine whether the number is prime or not. | |
(For those who have forgotten, a prime number is a number that has no divisors.) | |
''' | |
def check_primary(num): | |
result = True | |
for j in range(2,num): | |
if num % j == 0: | |
result = False | |
return result | |
input_num = int(input("Input Prime to Show : \n > ")) | |
list_primary = [] | |
for i in range(2,input_num): | |
result = check_primary(i) | |
if result: | |
list_primary.append(i) | |
print(list_primary) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment