Skip to content

Instantly share code, notes, and snippets.

@jerrypy
Created November 2, 2017 07:25
Show Gist options
  • Save jerrypy/d18b457fc49e5e064fafedfdb4bff052 to your computer and use it in GitHub Desktop.
Save jerrypy/d18b457fc49e5e064fafedfdb4bff052 to your computer and use it in GitHub Desktop.
MIT 6.00 Assignments solutions
'''
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