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

I've got everything working on ps1, except my program doesn't find 2 as a prime. My brain is spent - can someone explain what I'm doing wrong? primesFound = 1 testMe = 1 while primesFound < 1000: for divisor in range(2,testMe): remainder = testMe % divisor if testMe%2 == 0: break if remainder == 0: prime = False break if divisor == testMe-1: print str(testMe) + " is a prime number." primesFound = primesFound + 1 testMe = testMe + 1

OpenStudy (anonymous):

edit = the "if testMe%2 == 0: break" shouldn't be in there, I was just testing it. I understand that it's skipping 2 because the remainder works out to 0 on the first loop, but when I change the range to start at 1, then the entire program doesn nothing.

OpenStudy (anonymous):

Can you repost your code using dpaste.com. or attach them?

OpenStudy (anonymous):

Actually I got it working... :) Should I still post it?

OpenStudy (anonymous):

No but next time when you post your code either attach a file or put it on dpaste.com and post the link because when you just post it in the message when we copy it to a file the indentations are all gone and it all goes on one line.

OpenStudy (anonymous):

That's odd, it copies perfectly for me. Thanks

OpenStudy (anonymous):

Maybe it's because I'm running linux. I'm not sure though.

OpenStudy (anonymous):

I just want to add that in Firefox if you highlight the script you want to copy, right-click and select "View Selection Source", a window will pop up with the script text already highlighted. You can then copy from that and paste into Python and it will keep the proper formatting. If you don't use Firefox, perhaps there's a similar function in your browser. Just wanted to share in case you find it useful.

OpenStudy (anonymous):

Thanks yea I knew about the source but I would of never thought to use it for that very creative haha

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!