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

Here is my code for problem set 1b. Can someone please let me know if it calculates everything accurately? http://codepad.org/P3hES3WI

OpenStudy (anonymous):

Works fine, at least in comparison to mine. Kudos for the solution :-)

OpenStudy (anonymous):

Thanks!!

OpenStudy (anonymous):

Just a commentary: avoid using 'from module import *' syntax. It works fine, but it may cause some collision with some other function already imported/implemented, i.e. if you have already a function named log, it would create some problems. Refer to: http://effbot.org/zone/import-confusion.htm

OpenStudy (anonymous):

Is there another way to get the log function?

OpenStudy (anonymous):

import math. You will have to write math.log, and it works fine.

OpenStudy (anonymous):

Can you show me exactly how that would appear in the script?

OpenStudy (anonymous):

http://codepad.org/xx6NPQhD I imported it at the top, rather than hidden in the middle of the code also.

OpenStudy (maitre_kaio):

I've noted one little thing: you are testing redundant checks with current_candidate < current_tester*2 It's all right, but it's more efficient with current_candidate < current_tester * current_tester since you only have to check until the square root of current_candidate. One more thing: why not write log_total = math.log(2) instead of log_total=0.69314718055994529 ? This way it's more readable and less error prone.

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!