A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • one year ago

This is what I have for ps1a. Am I even close? Also, I keep getting syntax errors for False, why? for x in range (2, 3000): is_Prime=True for y in range (2, 3000): if x % y == 0: is_Prime False

  • This Question is Open
  1. e.mccormick
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    What is the example assignment? It has been a while since I looked at them...

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

    It is Write a program that computes and prints the 1000th prime number. Any help would be greatly appreciated!!

  3. e.mccormick
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Basically, a simple prime test is to try and divide a number by other numbers. However, you can make it faster by using a little logic. For example, you can skip all even numbers after 2 because none of them are prime, so the number to be tested can be advanced by 2 each time. Just be sure to adjust your number of primes found up by 1 to account for knowing 2 is not there. Also, you can't divide anything evenly by more than half its value, so you can make the code skip the division of numbers that are greater than half of the number being tested. There are other ways, but if uoi focus on those you can get something that does a resonable number of tests. Each time you get a result, advance the number of primes found. Then the number of primes found reaches 1000, stop testing and print the result. The 1000th prime is 7919. But your program might miss and be a bit over and under, so here are some numbers from a list of 10000 primes. I took the 2 lines that have the 9 before and 10 after that: 7841 7853 7867 7873 7877 7879 7883 7901 7907 7919 7927 7933 7937 7949 7951 7963 7993 8009 8011 8017 It is from this list: https://primes.utm.edu/lists/small/10000.txt

  4. rsmith6559
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The last line: is_Prime False should be: is_Prime = False

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

    Thanks rsmith6559!

  6. e.mccormick
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    oops... I missed that simple one.

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