A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 4 years ago
In the 2nd assignment, one of the tips to generate the prime numbers was to generate all odd integers >1. Where can I store the generated list? Aren't we only allowed to use conditional statements, loops and variables?
anonymous
 4 years ago
In the 2nd assignment, one of the tips to generate the prime numbers was to generate all odd integers >1. Where can I store the generated list? Aren't we only allowed to use conditional statements, loops and variables?

This Question is Closed

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Instead of generating all odd integers, I think most people tend to only test negative integers by starting with 3 and then increasing by 2 each time. That way you only test odd numbers, but you don't have to generate a list of odd numbers at the beginning.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0You have several questions rolled into one. Let's take each question in turn. 1) "Aren't we only allowed to use conditional statements, loops and variables?" You are not restricted to any particular technique as long as you solve the problem. 2) The use of the word "generate" is unfortunate. The purpose of the exercise is to check integers for primality. Since we know that the even numbers are all composite (divisible by 2) we can with one fell swoop eliminate from the test. By "generating" prime numbers the mean only check the odd numbers for primality. You can do that using whatever technique. 3) "Where can I store the generated list?" For this assignment strictly speaking you don't need to store items in a list to solve the problem. However, for troubleshooting purposes and to verify that you are coming up the right results it's helpful to build that into your program initially. Let's say that you want to store the primes as you cycle through the set of odd numbers. You could a) declare an empty list called primes; b) append to that list as you come across a prime number; primes=[ ] the loop in your program which checks to see if num is indeed a prime number; if it is append it the list that stores the set of prime numbers primes.append(num)

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0I believe the short answer is that generating a list is not necessary. a brute force method may simply involve taking a number "x", and then attempting to divide by an increasing number "y". You can increase the value of "y" with a loop. You can increase the value of "x" with another loop. You needn't store all of these values you are generating. For some faster methods that may take advantage of concepts that are introduced later, you may see the discussion here: http://openstudy.com/study?F1244392739431MUOV2U=_#/updates/4f1241dbe4b0a4c24f583004
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.