Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

My Assignment 1 results - can anyone take a look and critique? http://pastebin.com/BC5JKCRc

OpenStudy (anonymous):

line 14: you shouldn't have to cast the log as a float it is already a float lines 11, 17, 20: consider using a boolean, and renaming it to isprime then line 20 can read "if isprime:" line 22 logcount is a float - you don't have to cast x as a float http://docs.python.org/tutorial/introduction.html#numbers http://docs.python.org/reference/expressions.html#arithmetic-conversions line 14: because of the placement of this expression, does line 23 reflect/print the logcount up to the previously found prime instead of the current prime? the first time through, logcount will be the log of 2 but x will be 3 when you get to line 23

OpenStudy (anonymous):

bwCA - first off thank you for the very detailed answer. I completely understand everything you mentioned except the last suggestion you offered, I'm not sure I see the error. From what I can see it keeps adding to the log count for every previously found prime.

OpenStudy (anonymous):

i didn't test it but tried to 'walk through' it. at line ten you enter a loop with x = 3 and primelist=[2] at line fourteen, logcount equals the log of 2 (only) x (3) is prime so at line twenty-two, ratio equals the log of two divided by 3 the next time it finds a prime (5) line 22 is (log(2) + log(3) ) / 5 logcount should be the sum of the logs of all the primes found so far (including the current prime). for the two cases above i think ratio should be: (log(2) + log(3) ) / 3 (log(2) + log(3) + log(5)) / 5

OpenStudy (anonymous):

When incrementing your candidate prime value, you should increment by 2 as opposed to one. The reason for this is that even numbers can never be prime since they are always divisible by 2. Therefore you only need to check odd numbers for primacy.

OpenStudy (anonymous):

bwCA - I didn't think the problem read that it was the sum of all logs including the current prime, I had read it as the sum of all the logs of the PREVIOUS primes divided by the current prime. I understand now what you mean. So the easiest fix would have been on line 22 to do: ratio = (logcount + log(x)) / x Zaclem01 - you are correct that would make things more efficient, I just wanted to be able to "test" every number from 2 through to n. Thank you to you both, when I complete the next assignment I hope you can give great pointers as well. This is my first attempt at MIT OCW and so far really liking it.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!