Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 30 Online
OpenStudy (anonymous):

Can someone please review my ps1b? I'd appreciate any feedback. import math def isPrime(num): if num > 1: if num == 2: return 1 i = 2 while i < math.sqrt(num) + 1: if num%i == 0: return 0 else: i += 1 return 1 else: return 0 def ps2(num): i = 2 j = 0 logsum = math.log(2) while j < num: if isPrime(i) == 1: j += 1 logsum += math.log(i) if j == num: print "N: ",num print "Sum of logs: ",logsum print "Ratio: ",num/logsum i = i + 1 ps2(input("Enter a number: "))

OpenStudy (anonymous):

sorry function ps2 should be called something like printLogInfo

OpenStudy (anonymous):

2 problems. 1) The ratio should be the (sum of logs not including the nth prime)/the nth prime. In your problem, you divide 1000 by the sum of logs including the nth prime. This is wrong. 2) Note that you must not include the math.log(7919) in your Sum. The sum should be close to 7803 I believe. 3) I checked your problem. You add math.log(2) twice in your problem. Remove one to get 7803.3 which is the correct answer.

OpenStudy (anonymous):

Thanks!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!