Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Programming help! Please provide the code for the following question. Two

ID: 3862998 • Letter: P

Question

Python Programming help! Please provide the code for the following question.

Two primes are said to be twins if they differ by 2. For example, 5 and 7, or 17 and 19. A prime is said to be palindromic if it reads the same backwards and forwards like 11. Write a function has_twins() that prints all three digit non-palindromic prime numbers that have twins. The twin could be bigger or smaller than the non-palindromic prime number. Print only the non-palindromic prime number but not the twin. Assume that the functions is_prime() and is_palindromic() have been written for you. def has_twin ():

Explanation / Answer

def has_twins():
    array = []
    index = 0
    for i in range(101,998):
        if(is_prime(i)):
            if(not(is_palindromic(i))):
                array.insert(index,i)
                index = index + 1
    new_array = []
    index1 = 0
    for i in range(0, index - 2):
        if(i < index-2):
            if(not(array[i+1] - array[i] == 2 or array[i] - array[i-1] == 2)):
                new_array.insert(index1,array[i])
                index1 = index1 + 1
                i = i + 1
    return new_array