Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
Migpics
Group Title
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,)
 one year ago
 one year ago
Migpics Group Title
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,)
 one year ago
 one year ago

This Question is Open

MicroBot Group TitleBest ResponseYou've already chosen the best response.0
Just 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
 one year ago

Migpics Group TitleBest ResponseYou've already chosen the best response.0
Thanks. 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
 one year ago

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

MicroBot Group TitleBest ResponseYou've already chosen the best response.0
what 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.
 one year ago

Migpics Group TitleBest ResponseYou've already chosen the best response.0
I'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.
 one year ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.0
Generate all (odd) integers > 1 u generate 1 aswell
 one year ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.0
ye ive done it aswell brb 5 mins
 one year ago

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

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

Migpics Group TitleBest ResponseYou've already chosen the best response.0
Oh right. Yeah, I see that. Will correct. Overthinking it.
 one year ago

Migpics Group TitleBest ResponseYou've already chosen the best response.0
Okay, gotta go. Will check on this later. :) thanks for the help.
 one year ago

MicroBot Group TitleBest 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?"
 one year ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.0
you are welcome ask me anytime:)
 one year ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.0
http://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.)
 one year ago

kris40k Group TitleBest ResponseYou've already chosen the best response.0
Another 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.
 one year ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.0
im pretty sure tuples were introduced..but i can be wrong...
 one year ago

Migpics Group TitleBest ResponseYou've already chosen the best response.0
I was just going by the recommended procedure in the assignment. This was my original attempt http://codepad.org/zOOA8ys4
 one year ago
See more questions >>>
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.