Can someone explain why my code for PSet1b isn't working? http://dpaste.com/566027/ There's no error, the ratio just doesn't approach 1.
i can't see it right off the bat, but I was wondering about your int(raw_input(... code on line 22. Is there a specific reason why you did that?
The int was to convert the raw input answer to an integer, because where I use x, it needs to be an integer. The line in general is just to give the user an option of how many times they would like to run the test (how many prime numbers).
it's because you are dividing by the number of prime numbers you've found. you are supposed to divide by the highest prime number that you've found. Also it's asking for you to show the prime numbers up to the number given (i.e. if I said 10, the highest prime number would be 7, then it would add the logs of 2,3,5,7 and divide by 10).
@austin: You do know that you could just use the input right? or were you anticipating some defensive programming for later?
yeah gothery is perfectly right...u have to divide the logsum by the largest prime number that is the nth prime number in ur case..then the ratio should approach 1. .everyone seems to be doing this...the question actually says take in number ...add up the logs of all the primes less than n and then divide the logsum by n... but everybody takes n as the number of prime numbers.. Anyways...but
That's pretty much it. The problem set clearly says: "Computes the sum of all the primes from 2 to some number n, and print out the sum of the logs of primes, the number n, and the ratio of these two quantities."
And where's the good answer button when you need it?
just a minute...i am damn sure i wrote another 2 lines after that last but...where the heck are they :( !!! all my hard work... >:(...missing :'(
ya austin, don't forget to give gothery his "good answer" mark...
i gave him one <(")
Join our real-time social learning platform and learn together with your friends!