Created
November 20, 2015 18:36
-
-
Save harshvb7/7536200d554cf95efb6a to your computer and use it in GitHub Desktop.
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
import math | |
l = input('Enter lowest no.') | |
h = input('Enter higest no.') | |
def check_prime(n): | |
if n < 2: | |
return False | |
for i in range(2, int(math.sqrt(n)) + 1): # see if num is divisible by any number up to the square root of num | |
if n % i == 0: | |
return False | |
return True | |
for i in range(l, h-1): | |
if check_prime(i) and check_prime(i+2): | |
print 'Smallest twins in given range: (%d %d)' %(i, i+2) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment