Deb


Joined 1 year ago
Homeworks submitted:
Homework comments:
2
0

About Me

No description provided.

Classes

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming

Class status: Established
Role: Student
. 11% complete

Submitted Assignments

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1

Assignment #1: Part 1 - Print the 1000th prime number Part 2 - Show that the ratio of the sum of log of primes < N and N approaches 1 as N gets larger

# Assignment #1 Part #1 - compute and print the 1000th prime number
# -----------------------------------------------------------------

# Assignment #1 - function to see if a number is prime
def isPrime(value):
	if value == 1: return False
	if value == 2: return True
	for i in range(3,value / 2,2):
		if (value % i) == 0:
			return False
	return True

# initilize the necessary variables
found = False 	 # tells us when to stop the loop
candidate = 3    # the initial value we are checking to see if it is prime
count = 1        # the count of prime numbers we've found, start at 1 because 2 is a prime

# continue until we've found 1000 primes
while( found == False ):

	if isPrime(candidate) == True:  	# loop thru all odd numbers less than half the candidate 
		count += 1       				# increment out counter of found prime numbers
	if count == 1000:    				# did we find our 1000 hit?
		print 'The 1000 prime number is:', candidate, '\n'
		found = True
	else:
		candidate += 2   				# increment our candidate and try again
		
# Assignment #1 Part #2 - Sum of log of primes < N and N ratio approaches 1 as N gets larger
import math

userValue = int(raw_input('Enter your value to calculate: '))

sumLogs = 0.0
for i in range(1,userValue,2):
	if isPrime(i) == True:
		sumLogs += math.log(i)
print '\nThe sum of the logs of the prime values less than', userValue, 'is:', sumLogs
print 'The ratio is:', sumLogs / userValue

Deb 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1

Assignment #0 - entering and printing your name

#Assignment #0 - entering and printing your name

FName = raw_input('Enter your first name: ')
LName = raw_input('Now, enter your last name: ')
print 'Your name is ' + FName + ' ' + LName

Deb 1 year ago