Dino3317OSU


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

About Me

Giving this a shot. Should have taken some of these classes when I was an undergrad/grad!

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

Got stuck on the first one for awhile. Turned out that I had forgotten to reset my testdiv to 2 when it found a number that wasn't prime. So it would go through the first 30 primes just fine but then when it got to 31 it would start returning non-prime numbers because testdiv was starting out higher than the number that would divide testnum evenly.

Problem 2 took about 25 minutes. Just needed to change it from a count down to a test to make sure your testnum was less than the number in question, n in this case. The other change was to make sure that when the system found a prime number that it added that number to a variable that I called sumlogs. This variable starts with a value of log(2) to account for 2 being left out of the test.

Don't forget to make sure your variables are properly configured as integers or floats.

#Problem Set 1
#Dino3317OSU

##Problem 1


prime = raw_input('Which prime # would you like to know? ')

testnum=3
testdiv=2
count=int(prime)-1

while count>0:
    if testnum==testdiv:
        count=count-1
        testnum=testnum+2
        testdiv=2
    else:
        if testnum%testdiv==0:
            testnum=testnum+2
            testdiv=2
        else:
            testdiv=testdiv+1
else:
    print testnum-2, 'is #', prime


##Problem 2.


from math import *

n = raw_input('What is n? ')

testnum=3
testdiv=2
sumlogs=log(2)

while testnum<int(n):
    if testnum==testdiv:
        sumlogs=sumlogs+log(testnum)
        testnum=testnum+2
        testdiv=2
    else:
        if testnum%testdiv==0:
            testnum=testnum+2
            testdiv=2
        else:
            testdiv=testdiv+1
else:
    print 'The sum of all the prime logs under ',n,' is ',sumlogs
    print 'The ratio is', float(sumlogs)/float(n)

Dino3317OSU 4 months ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1
# Problem Set 0
# Dino3317OSU


first = raw_input('What is your first name? ')
last = raw_input('What is your last name? ')
print 'Your name is:', first, last

Dino3317OSU 4 months ago