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
What is the example assignment? It has been a while since I looked at them...
It is Write a program that computes and prints the 1000th prime number. Any help would be greatly appreciated!!
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
The last line: is_Prime False should be: is_Prime = False
Thanks rsmith6559!
oops... I missed that simple one.
Join our real-time social learning platform and learn together with your friends!