Here is my code for problem set 1b. Can someone please let me know if it calculates everything accurately? http://codepad.org/P3hES3WI
Works fine, at least in comparison to mine. Kudos for the solution :-)
Thanks!!
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
Is there another way to get the log function?
import math. You will have to write math.log, and it works fine.
Can you show me exactly how that would appear in the script?
http://codepad.org/xx6NPQhD I imported it at the top, rather than hidden in the middle of the code also.
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.
Thanks!!!
Join our real-time social learning platform and learn together with your friends!