MIT 6.00 Intro Computer Science (OCW) OpenStudy (anonymous):

Problem Set 1.1 ends with a non-prime number? My Code: # Problem Set 1 # Name: Cody Dostal # Collaborators: None # Time: 0:30 # PotentialPrime = 1 divider = 2 primecount = 1 while primecount < 1000: PotentialPrime = PotentialPrime + 2 divider = 2 isnotprime = 0 while divider <= (PotentialPrime/2) and isnotprime == 0: if PotentialPrime%divider == 0: isnotprime = 1 else: divider = divider + 1 if isnotprime == 0: primecount = primecount + 1 print "Potential 1000th prime: " + str(PotentialPrime) + " " + "Prime Count: " OpenStudy (anonymous):

It ends with 7919, which 7919/3 = 2639 and 2639 * 7917 = Woooooooah? hahah OpenStudy (anonymous):

I mean, 2639 * 3 = 7917 = Woaaaaaaaaaaah? OpenStudy (anonymous):

7919/3 is not exactly 2639. It is 2639.6666667. There is a remainder, so is not the same as 2639.0*3. OpenStudy (anonymous):

Yeah, 7919 is correct. Good job! Also, if you dedent the print line all the way out of the first while statement, it will only print the last number. Aslander was pointing out that the way integer division works isn't the way division of real numbers(floats) works. according to integer division, for instance, 5/3 = 1. If you check specifically, you'll find that it's actually 1 modulo(meaning "with the remainder") 2, but the basic thing to understand is that if you divide an integer by another integer, you'll ALWAYS get another integer, regardless of what the answer would be if you were using real numbers. OpenStudy (anonymous):

Thanks. That's crazy, I forgot Python is like that... So if I wanted to show it is prime, I would have to do 7919.0/3? Would that end with showing it is a prime? Thanks! OpenStudy (anonymous):

I'm not sure what you mean by "showing it is a prime." Why would trying to divide it by 3 show that it's prime? OpenStudy (anonymous):

I mean that, to show it is not divisible by 3 as well? I just want to know that real quick for future programs xD OpenStudy (anonymous):

well, if you want to know that a number is NOT evenly divisible by another number, you can check the remainder. So the statement x%3 != 0 would return False if x was evenly divisible by 3 because if it was, the remainder would be 0. the % sign (called the modulo) returns the remainder from integer division. OpenStudy (anonymous): OpenStudy (anonymous):

@somnamniac: Thank you so much :) I'll edit my code when I'm home and see how that works out :) @Aslander: Huh? hahha OpenStudy (anonymous):

lol - ya for some reason I replied on your question when it was for someone else :-) Sorry dude! Although it is on the same subject... OpenStudy (anonymous):

Yeah haa. I got very confused because of the MAX statement not being in my code, :) That definitely would help, however :)

Latest Questions billiejean: The scatter plot shows the ages of people at a retreat and the number of events they participated in.
20 minutes ago 1 Reply 0 Medals yensteng: A 25.0 kg child on a swing kicks upward on the downswing thus changing the distance from the pivot point to her centre of gravity from 2.
38 minutes ago 0 Replies 0 Medals khozynhodges68: Find the length of the hypotenuse of an isosceles right triangle whose legs are 1 unit in length.
37 minutes ago 2 Replies 0 Medals LakersForever865: Is anyone upppppppp ?? i need helppp
53 minutes ago 0 Replies 0 Medals ZackAttack042704: If I weigh 99 pounds and eat 1 pound if nachos. Does that make me 1% nachos?
54 minutes ago 0 Replies 0 Medals jmjmjm18: An astronaut in orbit outside an orbiting space station throws her 800-g camera away when it jams.
1 hour ago 0 Replies 0 Medals TannerH2004: what is the phenotype frequency? A) the total number of genes in a population B)
1 hour ago 0 Replies 0 Medals gababb09: Find the value of the following expression: $(2^8u00d7~5^{-5}~u00d719^0)^{-2}u00d7\left(\begin{matrix}5^{-2} \\ 2^{3}\end{matrix}\right)^{4}u00d72^{28}$ W
54 minutes ago 10 Replies 2 Medals Drdynamic: On a journey, a cyclist travelled 1 kilometre in x minutes. On a second journey, the cyclist travelled for y hours at the same average speed as on the first
2 hours ago 0 Replies 0 Medals