A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
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 == testMe1:
print str(testMe) + " is a prime number."
primesFound = primesFound + 1
testMe = testMe + 1
anonymous
 5 years ago
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 == testMe1: print str(testMe) + " is a prime number." primesFound = primesFound + 1 testMe = testMe + 1

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0edit = 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Can you repost your code using dpaste.com. or attach them?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Actually I got it working... :) Should I still post it?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0No 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0That's odd, it copies perfectly for me. Thanks

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Maybe it's because I'm running linux. I'm not sure though.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I just want to add that in Firefox if you highlight the script you want to copy, rightclick 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Thanks yea I knew about the source but I would of never thought to use it for that very creative haha
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.