Question

Twin primes are primes that are exactly two apart. For example, 41 and 43, are twin...

Twin primes are primes that are exactly two apart. For example, 41 and 43, are twin primes. (The two Bushes were twin prime presidents — I’m surprised nobody ever pointed that out!) Write a function twinprimes(primes) that takes as input a list of prime numbers and returns another list twins containing all the twin primes. Be sure to write your code in such a way that the list primes remains unaltered. (It is known that there are infinitely many prime numbers. It is thought that there are infinitely many twin primes, but this is not known for sure.)

Use python for code

Provide notes/comments as well for as many statements as possible

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def twinprimes(primes):
    result = []
    for p in primes:
        found = False
        for num in primes:
            if p - num == 2 or p - num == -2:
                found = True
        if found and p not in result:
            result.append(p)
    return result


print(twinprimes([17, 19, 29, 31, 27, 41, 47, 43]))

Add a comment
Know the answer?
Add Answer to:
Twin primes are primes that are exactly two apart. For example, 41 and 43, are twin...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA...

    Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA {    private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) {    Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...

  • Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignme...

    Coding for Python - The pattern detection problem – part 2: def calculate_similarity_list(data_series, pattern) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the given...

  • Mary Benninger had sought out her old friend, Tom Chu, to discuss her employment situation. Mary...

    Mary Benninger had sought out her old friend, Tom Chu, to discuss her employment situation. Mary and Tom had both graduated in 1985 from Mackenzie King University, and then studied together to attain their CMA designations in 1988. Soon thereafter, Tom was promoted quickly within his division of a large multi-national auto supply company, and now held the position of vice-president/controller. Mary, on the other hand, had temporarily removed herself from full-time employment in 1990 to raise her young daughter....

  • Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold) Plea...

    Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the...

  • This is in C. For this assignment we will write a simple database server. We will...

    This is in C. For this assignment we will write a simple database server. We will be creating a simple database of student records, so let’s describe these first. The format of a student record is as follows: typedef struct student {     char lname[ 10 ], initial, fname[ 10 ];     unsigned long SID;     float GPA; } SREC; Part One – the Server We will create a database server. The job of the server is to accept a...

  • internal project 1 anything helps! thank you!! Instructions: Study the case that starts on page 3...

    internal project 1 anything helps! thank you!! Instructions: Study the case that starts on page 3 carefully. Then write concise answers to the following questions regarding the internal control system of Duarf, Inc. Clearly label your responses with proper headings and subheadings. Be very specific and precise. Answers that appear to be beating around the bush will not get any credit. 1. What are the controls in place that under normal conditions should function well to prevent embezzlements or frauds?...

  • Hi there! I need to compare two essay into 1 essay, and make it interesting and...

    Hi there! I need to compare two essay into 1 essay, and make it interesting and choose couple topics which im going to talk about in my essay FIRST ESSAY “Teaching New Worlds/New Words” bell hooks Like desire, language disrupts, refuses to be contained within boundaries. It speaks itself against our will, in words and thoughts that intrude, even violate the most private spaces of mind and body. It was in my first year of college that I read Adrienne...

  • Rachel's Story A mothers' account of raising a transgendered child Rachel's mother is the author of...

    Rachel's Story A mothers' account of raising a transgendered child Rachel's mother is the author of this story. She writes about the first few years of Rachel's life when she was known as Ryan. This is the story of how Ryan became Rachel. Rachel is a beautiful, well-adjusted, happy and healthy nine year old little girl. She likes to do all the things little girls at this age like to do. Sleepovers and ice-cream sundaes are by far her favorite...

  • Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of...

    Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of physician-centered and collaborative communication. How is the caregiver’s role different in each model? How is the patient’s role different? Answer: Physical-centered communication involves the specialists taking control of the conversation. They decide on the topics of discussion and when to end the process. The patient responds to the issues raised by the caregiver and acts accordingly. On the other hand, Collaborative communication involves a...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT