forked from Pritam-Pagla/playingwithprimes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculateNTPP.py
34 lines (28 loc) · 976 Bytes
/
calculateNTPP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def primeTest(x):
for divisor in range(2,x):
if x%divisor == 0:
# x is non prime
return False
return True
def calculate_NTPP(y,z): # y=lower-bound & z=upper bound
primes_within=[]
for integer in range(y,z):
if(primeTest(integer)==True and primeTest(integer+2)==True):
primes_within.append(str(integer)+','+str(integer+2))
ntpp = len(primes_within) # ntpp = Number of Twin Prime Pairs
return ntpp
primes_within=[]
def determine_pairs(y,z): # y=lower-bound & z=upper bound
primes_within=[]
for integer in range(y,z):
if(primeTest(integer)==True and primeTest(integer+2)==True):
primes_within.append(str(integer)+','+str(integer+2))
return primes_within
primes_within=[]
print("\n")
lb = 2
ub = int(input("Enter the upper bound: "))
print("\n")
print(calculate_NTPP(lb,ub))
print("\n")
print(determine_pairs(lb,ub))