Argher


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 1, HW 1

I decided to do it slightly differently, just for kicks. As differently as you can get with this, anyway.

print "Enter your last name:"
a = raw_input()
print "Enter your first name:"
b = raw_input()
print b, a

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

I enjoyed this - tried to write a solution that was easy to read and understand. I made it a bit more flexible to test for any number rather than just 1000.

#Problem Set 1a ( Problem 1 )

primeswanted = int(input("This program will find the nth prime. \nPlease enter n:"))
if primeswanted <=0:
        print "n must be >= 1"
else:
        lastprime = 2
        primesfound = 1
        primecandidate = lastprime + 1 
        while primesfound < primeswanted: # range of search
            possibly_prime = True 
            for divisor in range(2, primecandidate, 1): # testing
                if possibly_prime:
                    possibly_prime = ((primecandidate % divisor) != 0) # testing continued
            if possibly_prime:
                lastprime = primecandidate  # moving the marker
                primesfound = primesfound + 1 
            primecandidate = primecandidate + 1
print "The nth prime is:", lastprime

#Problem Set 1b ( Problem 2 )

from math import *

primeswanted = int(input("This program will sum logs of primes through the nth and give the ratio between the sum and n.\nPlease enter n:"))
if primeswanted <=0:
        print "n must be >= 1"
else:
        lastprime = 2
        primelogs = log(2) # giving initial value for primelogs
        primesfound = 1
        primecandidate = lastprime + 1 
        while primesfound < primeswanted: 
            possibly_prime = True 
            for divisor in range(2, primecandidate, 1): # searching
                if possibly_prime:
                    possibly_prime = ((primecandidate % divisor) != 0) # testing
            if possibly_prime:
                lastprime = primecandidate  # moving the marker
                primesfound = primesfound + 1 
                newprimelog = log(primecandidate)
                primelogs = primelogs + newprimelog # summing the logs of primes
            primecandidate = primecandidate + 1
print "The sum of the logs of the primes is:", primelogs
print "The number of primes was (or n equals):", primeswanted
print "The ratio between the sum of the logs of primes and n is:", primelogs / primeswanted

Argher 1 year ago