Created
July 14, 2019 21:35
-
-
Save adityasuseno/faab296dff91a4f6a77316fc8ac7dcb0 to your computer and use it in GitHub Desktop.
Simple program to check whether a given number is prime or not
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 | |
#Simple program to check whether a number is prime or not | |
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('input Number: ')) | |
break | |
except ValueError: | |
print('Please Enter Number Only!') | |
print(isPrime(r)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment