anonymous
  • anonymous
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%(i-1))==0: primeList = primeList + (i,)
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
MicroBot
  • MicroBot
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
anonymous
  • anonymous
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
MicroBot
  • MicroBot
btw your code excludes 2 as a prime...2 IS a prime...so think on that too.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

MicroBot
  • MicroBot
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.
anonymous
  • anonymous
I'm basically going by the problem set task presented here. http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/assignments/pset1a.pdf It says to first make a list of odds, then start sifting through that.
MicroBot
  • MicroBot
Generate all (odd) integers > 1 u generate 1 aswell
MicroBot
  • MicroBot
ye ive done it aswell brb 5 mins
anonymous
  • anonymous
x=100 oddTuple = (1,2) for i in range(2,x): if (i%2) == 1: oddTuple = oddTuple + (i, ) print oddTuple
MicroBot
  • MicroBot
nono your oddtuple has to have odd numbers >1 (bigger than 1) means: (3,5,7,.....) but your primetuple must have 1 and 2
anonymous
  • anonymous
Oh right. Yeah, I see that. Will correct. Overthinking it.
anonymous
  • anonymous
Okay, gotta go. Will check on this later. :) thanks for the help.
MicroBot
  • MicroBot
"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
  • MicroBot
you are welcome ask me anytime:)
MicroBot
  • MicroBot
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.)
anonymous
  • anonymous
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.
MicroBot
  • MicroBot
im pretty sure tuples were introduced..but i can be wrong...
anonymous
  • anonymous
I was just going by the recommended procedure in the assignment. This was my original attempt http://codepad.org/zOOA8ys4

Looking for something else?

Not the answer you are looking for? Search for more explanations.