Computers and Technology

Prime numbers (with the exception of 2) are always odd; so, aside from 2 and 3, the smallest possible difference between consecutive prime numbers is 2. For instance, 5 and 7 are primes, and 7 - 5 = 2; 11 and 13 are primes, and 13 - 11 = 2; 17 and 19 are primes, and 19 - 17 = 2; etc. Two primes that differ by 2 are called twin primes. It has been known since antiquity that there are infinitely many prime numbers; however, it is still unproven that there are infinitely many twin prime pairs. (That is, it is unproven that the list that starts with (3,5), (5,7), (11,13), (17,19), (29,31), (41,43), . . . never ends.) Interestingly, huge progress was made four years ago by an until-then-unfamous mathematician named Yiteng Zheng.

Your first mission is to create a function called is prime. This function should take a positive integer as input, and return True if it has exactly two factors, and False otherwise. In my twins. py file, I have kindly put some text code, so that you can see if your function is working properly - none of the lines should say ERROR!.

Once your function is working, delete my code. Your next mission is to create a program that asks the user to provide two positive integers P and Q. Your program should print all the twin prime pairs that lie between P and Q, inclusive. So, for example, if the user enters 11 and 43, the program should output (11,13), (17,19), (29,31). (41, 43). If the user enters 11 and 41, the program should just output (11,13), (17,19), (29, 31), since 43 isn't between 11 and 41.

The simplest way to do this is, roughly, go through the integers from P to Q: for each number, determine whether that number and that number plus 2 are both prime. Of course, it is up to you to get all the details right.

Specifications: your program must

1. write a function called is prime, which takes a positive integer, and returns the value True if the integer is prime, and False if the integer is not prime. (It only needs to work for positive integers, note that 1 is technically not prime!)
2. ask the user to enter in two positive integers, P and Q.
3. print out all pairs of twin primes where both the primes are between P and Q inclusive.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, marvezunderwood
When determining the classification of data, which one of the following is the most important consideration? a. processing systemb. valuec. storage mediad. accessibility
Answers: 2
image
Computers and Technology, 22.06.2019 06:30, gracie2492
What result from the passage of this amendment
Answers: 1
image
Computers and Technology, 22.06.2019 13:00, Cookie320
Write a program which asks you to enter a name in the form of first middle initial last. so you might enter for example samuel p. clemens. use getline to read in the string because it contains spaces. also, apparently the shift key on your keyboard doesn’t work, because you enter it all lower case. pass the string to a function which uses .find to locate the letters which need to be upper case and use toupper to convert those characters to uppercase. the revised string should then be returned to main in the form last, first mi where it will be displayed.
Answers: 1
image
Computers and Technology, 24.06.2019 13:30, livie225
Type the correct answer in the box. spell all words correctly. what is the default margin width on all four sides of a document? by default, the document has a margin on all four sides.
Answers: 1
Do you know the correct answer?
Prime numbers (with the exception of 2) are always odd; so, aside from 2 and 3, the smallest possibl...

Questions in other subjects: