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

http://codepad.org/YTuwHQGC just tried my hand at PS1, Though I would prefer to use a user input number as opposed to 1000, which is why I used variable Y. What do you think?

OpenStudy (anonymous):

Looks good. Only critique I can think of is that, for your FindPrime(n), if n < 2 it will say n is prime: http://codepad.org/IwzsOUlT Other than that, line 18 of your code is redundant and it works fine without it. See: http://codepad.org/2EbjqwTJ

OpenStudy (anonymous):

I see what you mean. Would this mean that 7919 is not the real solution? In addition, what is a good fix for this?

OpenStudy (anonymous):

http://codepad.org/VqJ9Gdfs. Added n < 2 to the first if statement. I am certain that there is a better way to do this though--because when I try this in the full code, it says that 1001 is the 1000th prime number.

OpenStudy (anonymous):

7919 is the right answer. Your first code works and solves the problem, there were just some things that could be tweaked to make it better.

OpenStudy (anonymous):

Okay. I think I'll try the second part of this problem. Has anybody tried it yet?

OpenStudy (anonymous):

Lots of folks have tried it. I've finished all the problem sets, and I know some other people who've been on here recently are at around 5 or 6. Your last codepad post is now a 404. I had a bunch of mine do that too. I just had to repost them. Based on what you said you did, though, I think I can see what the problem is. Your condition is now if n < 2 and n % x == 0: Add a print statement right before that line so you can see what n and x are when (and if) you get there.

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!