A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 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 == testMe-1: print str(testMe) + " is a prime number." primesFound = primesFound + 1 testMe = testMe + 1

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  9. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.