Help with if statement

Paul Rubin http
Sun Jan 11 14:37:46 EST 2004


"Jikosan" <jikosan at myrealbox.com> writes:
> for N in range(0, 100000, 25):

For such a large list, you should xrange instead of range.  That will
use less memory.

>         c = math.sqrt(math.pow(x,2.0) + math.pow(y,2.0))

You should use "c = math.sqrt(x*x + y*y)" which is both faster and
more flexible: math.pow(x,2.0) happens to work ok here, but can throw
an error in some implementations if x is negative.

>     pi = 4.0*(onecheck*math.pow(N,-1)) 

You can say "pi = (4.0 * onecheck) / N" here.  That's faster and more
straightforward.  

> #Convert pi and N to log10 and write to a file to graph on Excel.

Why are you going to graph log(N) vs log(pi)?  Do you expect them
to have an exponential relationship?  If not, log(N) vs pi, instead
of log(pi), may make more sense.



More information about the Python-list mailing list