A community for students.
Here's the question you clicked on:
 0 viewing
 2 years ago
This is for problem set 1 of the course where one needs to generate primes. I created a list of Odds and now want to go through that list to generate the primes. I'm a bit stumped on that. I know to divide the number with previous numbers in the list but am stuck on syntax. x=100oddList = ()for i in range(1,x): if (i%2) == 1: oddList = oddList + (i, )print oddListprimeList = ()for in in oddList: if (i%(i1))==0: primeList = primeList + (i,)
 2 years ago
This is for problem set 1 of the course where one needs to generate primes. I created a list of Odds and now want to go through that list to generate the primes. I'm a bit stumped on that. I know to divide the number with previous numbers in the list but am stuck on syntax. x=100oddList = ()for i in range(1,x): if (i%2) == 1: oddList = oddList + (i, )print oddListprimeList = ()for in in oddList: if (i%(i1))==0: primeList = primeList + (i,)

This Question is Open

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0Just a correction: oddList = () ###this is a tuple not a list! a list would be: oddList = [] (i know that at this point u probably must use tuples, but i just wanted to specify this difference) plus: for in in oddList: ####should be: for i in oddList: ###typo those for now...working on how to help u best in the meantime:P

Migpics
 2 years ago
Best ResponseYou've already chosen the best response.0Thanks. I'm just trying to get an understanind of this instead of blindly typing in code. My though process is that I want to run through each number in my tuple and divide that by the previous numbers. If any of those return a remainder of 0, then that means it's not a prime and I can move on. The question is how to iterate through the numbers beneath the selected number. Thanks Miguel

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0btw your code excludes 2 as a prime...2 IS a prime...so think on that too.

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0what you are trying to do can be done by using a for loop inside a for loop ...but i think it is very complicated....i mean there are other ways to see if a number is prime.

Migpics
 2 years ago
Best ResponseYou've already chosen the best response.0I'm basically going by the problem set task presented here. http://ocw.mit.edu/courses/electricalengineeringandcomputerscience/600introductiontocomputerscienceandprogrammingfall2008/assignments/pset1a.pdf It says to first make a list of odds, then start sifting through that.

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0Generate all (odd) integers > 1 u generate 1 aswell

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0ye ive done it aswell brb 5 mins

Migpics
 2 years ago
Best ResponseYou've already chosen the best response.0x=100 oddTuple = (1,2) for i in range(2,x): if (i%2) == 1: oddTuple = oddTuple + (i, ) print oddTuple

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0nono your oddtuple has to have odd numbers >1 (bigger than 1) means: (3,5,7,.....) but your primetuple must have 1 and 2

Migpics
 2 years ago
Best ResponseYou've already chosen the best response.0Oh right. Yeah, I see that. Will correct. Overthinking it.

Migpics
 2 years ago
Best ResponseYou've already chosen the best response.0Okay, gotta go. Will check on this later. :) thanks for the help.

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0"You might think about which integers you need to check as divisors – certainly you don’t need to go beyond the candidate you are checking, but how much sooner can you stop checking?"

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0you are welcome ask me anytime:)

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0http://primes.utm.edu/lists/small/1000.txt if u see here your 1000th prime must be 7919, but only if u dont count 1 as a prime (http://en.wikipedia.org/wiki/Prime_number#Primality_of_one) .(primetuple starts from 2.)

kris40k
 2 years ago
Best ResponseYou've already chosen the best response.0Another thing to keep in mind is that the problem set was due to be turned in before the concepts of tuples and lists had been introduced to the class. When I wrote my code I purposely kept this in mind and avoided using lists which I feel would have allowed for more efficient code. Perhaps approaching it from this angle would give you a fresh perspective of the problem and possible solution.

MicroBot
 2 years ago
Best ResponseYou've already chosen the best response.0im pretty sure tuples were introduced..but i can be wrong...

Migpics
 2 years ago
Best ResponseYou've already chosen the best response.0I was just going by the recommended procedure in the assignment. This was my original attempt http://codepad.org/zOOA8ys4
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.