Question: My language is python 3. Two consecutive primes are said to be twin primes if they differ by 2. For example (11,13), (17,19) are twin

My language is python 3.

Two consecutive primes are said to be "twin primes" if they differ by 2. For example (11,13), (17,19) are twin primes, one of each pair being the twin of the other. Write a boolean function, isTwinPrime(n), which returns True if n is a twin prime to another prime & which returns False otherwise. For example, isTwinPrime(11) and isTwinPrime(13) will both return True, but isTwinPrime(31) and isTwinPrime(15) will both return False. Plan on using isPrime as a helper function. Hint: to check whether a number, n, is prime you only have to check for divisibility for factors up to sqrt(n), rounded up to the next highest integer. If no factors are <= this largest factor, n is prime. This will speed things up. Sample run:

for n in range(1,50):

if isTwinPrime(n):

print(n, end = ', ')

>>>

Q1

3, 5, 7, 11, 13, 17, 19, 29, 31, 41, 43,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!