Created
November 2, 2017 07:25
-
-
Save jerrypy/d18b457fc49e5e064fafedfdb4bff052 to your computer and use it in GitHub Desktop.
MIT 6.00 Assignments solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Problem 1 a | |
Write a program that computes and prints the 1000th prime number. | |
''' | |
from math import sqrt | |
def is_prime(num): | |
i = 2 | |
while i <= sqrt(num): | |
if num % i == 0: | |
return False | |
i += 1 | |
return True | |
idx = 1 | |
n = 1 | |
while True: | |
if is_prime(n): | |
if idx == 1000: | |
print n | |
break | |
idx += 1 | |
n += 1 | |
# 7919 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment