Jaamoka


Joined 10 months ago
Homeworks submitted:
Homework comments:
2
0

About Me

No description provided.

Classes

Bulletproof Web Design

Class status: Established
Role: Student
. 0% complete

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

It makes sense to me and it works. I'm sure it could be much better but I'm just learning. All input is appreciated.

# Problem 1A
number=2
prime=1
# Loop through for all numbers
while (prime < 1000):
    # check if number is even
    if (number % 2 == 1):
        # test for prime numbers
        n = 2
        while (n <= (number**.5)):
            # if not prime break loop
            if (number % n == 0):
                break
            # otherwise contine through possibilities
            else:
                n = n + 1
        # none prime increments counter
        if (number % n == 0):
            number = number + 1
        # primes increments prime counter
        else:
            prime = prime + 1
            # print prime, ' : ', number # test
    # none prime increments counter
    number = number + 1
# Print 1,000th Prime
print number - 1

# Problem 1B
import math
number=2
prime=1
primes=(2,)
# Loop through for all numbers
while (prime < 1000):
    # check if number is even
    if (number % 2 == 1):
        # test for prime numbers
        n = 2
        while (n <= (number**.5)):
            # if not prime break loop
            if (number % n == 0):
                break
            # otherwise contine through possibilities
            else:
                n = n + 1
        # none prime increments counter
        if (number % n == 0):
            number = number + 1
        # primes increments prime counter
        else:
            # adds primes to a tuple
            primes = primes + (number,)
            prime = prime + 1
            # print number # test
    # none prime increments counter
    number = number + 1
# Print 1,000th Prime from the last index of a tuple
print (str(primes [-1]) + " is the 1,000th Prime Number")
#Compute the sum of all the logs of primes from 2 to N (some number).
print ("(The Sum, The Prime, The Ratio)")
total = 0
for N in primes[:]:
    total = math.log(N) + total
    if (N == primes[99]):
        print (total, primes[99], float(total/primes[99]))
    if (N == primes[250]):
        print (total, primes[250], float(total/primes[250]))
    if (N == primes[500]):
        print (total, primes[500], float(total/primes[500]))
    if (N == primes[750]):
        print (total, primes[750], float(total/primes[750]))
# Print the sum, the number N, and the ratio of the two
print (total, primes[-1], float(total/primes[-1]))

Jaamoka 7 months ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1
last = raw_input("What is your last name?")
first = raw_input("What is your first name?")
print("Your name is " + first + " " + last)

Jaamoka 7 months ago