Produce a list named primes which only contains the central number of two twin primes in the range [2,1000]. (A twin prime is a prime number which has another prime number two away from it, like 41 and 43; in this case, we would add the number 42 to our list.) We provide a function is_prime to assist you with this. Call it like this: is_prime( 5 ).

Respuesta :

Answer:

def is_prime(x):

for i in range(2,x):

if x%i==0:

return False

return True

primes=[]

for i in range(2,1001):

# print(i,is_prime(i),is_prime(i+2))

if is_prime(i) and is_prime(i+2):

primes.append(i+1)

print(primes)

Explanation: