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

I've been working on problem set 1 - Product of the Primes. Everything appears to be working okay, but I was just wondering if there are solutions anywhere that I can check to verify my code is producing the correct result?

OpenStudy (anonymous):

If the 1000th prime was 7919 and the ratio of, if I recall correctly, sum of logs by log of the sum is assintotically approaching 1, then you should be satisfied with your answer. Other than that, you can post your code so we can judge it and give some tips for improvements :-)

OpenStudy (anonymous):

treerock: bmp's suggestion to share your code is a great idea. You can attach the .py file to this thread. I'm attaching my versions of PS1 for you to compare. Please note that I am running Python 3.3 not 2.7. I think there should not be any difference. Hope this helps.

OpenStudy (anonymous):

Thanks a lot. Here is my code. For an input of 1000 it returns a ratio of 0.989599137916 so it appears to be approaching 1 (whether it's assintotical I've no clue :D).

OpenStudy (anonymous):

@ chribonn, I was viewing the first of the three codes you pasted. It was easy to follow (thanks to your easy explanations). However, I saw a line: for ChkNum in range(2, ChkPrime-1, 1). I understand it but I didn't get why the last "1" is there. Can you please explain it. Thank you!

OpenStudy (anonymous):

scorpionismification: actually the last 1 is unnecessary. it defines the step. If the last digit were 2 the number would be incremented by 1. The default is one.

OpenStudy (anonymous):

Ok. got it. But i think you meant; "if the last digit were 2, the number would be incremented by 2". Thank you! :)

OpenStudy (anonymous):

yep. Sorry.

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!