This turned out to be an adventure. I thought this would be quick but it takes a bit more time because you have to really think about the code for the first one. At least, I did. I think if I had sat down and tried it once, it could have coded it in 30 minutes, but because I thought it'd be easy and was doing it as an after thought, it took a bit longer.
The second part is very easy.
#Problem Set 1
#Name: Bigsonny
#Collaborators: None
#Time:A few days for problem 1 and a 10 minutes for problem 2
#
from math import *
###############Problem 1########################
#A program which computes and prints the 1000th prime numbber
#Ask user which prime # to compute
number = int(input("What prime number do you want to compute?"))
count = 1 #Keeps track of the number corresponding to the prime#
prime_candidate = 2 # candidate for prime number
prime_check = 2 # number to check if prime_candidate is prime
while count < number: #continues until the count equals the user's number
#This section is going to check if the prime_candidate is even
#If prime_candidate is even, it will make it odd by adding 1 to it
#If prime_candidate is odd, it will print the count and the prime_candidate
#It will then add 2 to teh prime_candidate to get to the next odd number
#It will also increase the count by 1
if prime_candidate % 2 == 0: #checks if it's an even number
print str(prime_candidate) + ' is even.'
prime_candidate += 1 #adds 1 to make it odd
else: #is odd
while prime_check< prime_candidate:
if prime_candidate % prime_check !=0:
prime_check +=1
else:
prime_candidate +=2
prime_check = 2
if prime_check == prime_candidate:
count +=1
prime_check =2
prime_candidate +=2
print "Count: " + str(count) + ". Prime candidate: " + str(prime_candidate-2)
#####################Problem 2####################################
#This program should compute the sum of the algorithms of the prime numbers from 2
#to some number n
#print out the sum of the logs of the primes, the number n and the ratio of these
#two quantities.
#This is just to make the output easier to read, so I'm going to label this problem 2
#and print a few lines of hash tags
print " "
print 30*"#"
print 10*"#"+"problem 2"+11*"#"
print 30*"#"
#Ask user which prime # to compute. In this case, we'll define number as n
number = int(input("What prime number do you want to compute?"))
count = 1 #Keeps track of the number corresponding to the prime#
prime_candidate = 2 # candidate for prime number
prime_check = 2 # number to check if prime_candidate is prime
sumOfLog = 0 #This variable will contain the sum of the logs
ratioOfLog = 0 #This variable will contain the ratio of the logs
while count < number: #continues until the count equals the user's number
#This section is going to check if the prime_candidate is even
#If prime_candidate is even, it will make it odd by adding 1 to it
#If prime_candidate is odd, it will print the count and the prime_candidate
#It will then add 2 to teh prime_candidate to get to the next odd number
#It will also increase the count by 1
if prime_candidate % 2 == 0: #checks if it's an even number
print str(prime_candidate) + ' is even.'
prime_candidate += 1 #adds 1 to make it odd
else: #is odd
while prime_check< prime_candidate:
if prime_candidate % prime_check !=0:
prime_check +=1
else:
prime_candidate +=2
prime_check = 2
if prime_check == prime_candidate: #found a log
#first let's ccompute the sum of the logs of the prime numbers
sumOfLog = sumOfLog + log10(prime_candidate)
#Thes now, we'll increase the values of the variables
count +=1
prime_check =2
prime_candidate +=2
#We can start by printing the prime number and corresponding count
print "Count: " + str(count) + ". Prime candidate: " + str(prime_candidate-2)
#We'll test to see if count and number are equal
print ' '
#Finally, we'll print the sum of the logs of the primes, n and then the ratio
ratioOfLog = sumOfLog/number
print "The sum of the logs of the prime is: " +str(sumOfLog)
print "The number \"n\" is: " + str(number)
print "and the ratio of the sum of the primes to the number n is: " +str(ratioOfLog)
#Problem Set 0
#Name: Bigsonny
#Collaborators: None
#Time: 0:00
#
#First we ask the user to enter his/her last name
lastName = raw_input('What is your last name?')
#Second we ask the user to enter his/her first name
firstName = raw_input('What is your first name?')
#Last, we print the user's first and last name
print (firstName +" "+lastName)