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, 22.06.2019 03:20, owoeli
Which of these is a benefit of social networking? oa. hiding your true identity from friendsob. avoiding talking to people in personoc. spending time with friends instead of studyingod. connecting with new people
Answers: 2
image
Computers and Technology, 22.06.2019 15:00, miracle9704
Atool that matches persoal skills qualities interests and talets to a career is called a
Answers: 1
image
Computers and Technology, 22.06.2019 18:00, Geo777
Suppose an astronomer discovers a large, spherical-shaped body orbiting the sun. the body is composed mostly of rock, and there are no other bodies sharing its orbit. what is the best way to categorize this body? a. planet b. moon c. comet d. asteroid
Answers: 1
image
Computers and Technology, 22.06.2019 21:40, tdahna0403
Develop a function to create a document in the mongodb database “city” in the collection “inspections.” be sure it can handle error conditions gracefully. a. input -> argument to function will be set of key/value pairs in the data type acceptable to the mongodb driver insert api call b. return -> true if successful insert else false (require a screenshot)
Answers: 2
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:

Konu
Mathematics, 12.03.2020 06:21
Konu
Chemistry, 12.03.2020 06:21
Konu
History, 12.03.2020 06:22