Popular recipes tagged "calculate"http://code.activestate.com/recipes/tags/calculate/2012-01-26T02:27:25-08:00ActiveState Code RecipesWasted Money Calculator (Python) 2012-01-26T02:27:25-08:00userendhttp://code.activestate.com/recipes/users/4179007/http://code.activestate.com/recipes/578026-wasted-money-calculator/ <p style="color: grey"> Python recipe 578026 by <a href="/recipes/users/4179007/">userend</a> (<a href="/recipes/tags/calculate/">calculate</a>, <a href="/recipes/tags/calculator/">calculator</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/money/">money</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/save/">save</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). Revision 2. </p> <p>Calculate the amount of money you waste on the unnecessary items you buy everyday. </p> Calculate Trailing Zeroes in a Factorial (Python) 2011-08-15T17:23:03-07:00Stijn de Graafhttp://code.activestate.com/recipes/users/4178055/http://code.activestate.com/recipes/577844-calculate-trailing-zeroes-in-a-factorial/ <p style="color: grey"> Python recipe 577844 by <a href="/recipes/users/4178055/">Stijn de Graaf</a> (<a href="/recipes/tags/calculate/">calculate</a>, <a href="/recipes/tags/calculation/">calculation</a>, <a href="/recipes/tags/factorial/">factorial</a>, <a href="/recipes/tags/trailing/">trailing</a>, <a href="/recipes/tags/zero/">zero</a>, <a href="/recipes/tags/zeroes/">zeroes</a>). </p> <p>Calculates the number of trailing zeroes on the end of x! when the user inputs x.</p> Calculate Pi using Monte Carlo Simulations in Python (Vectorized) (Python) 2011-02-17T22:35:46-08:00Zach Pacehttp://code.activestate.com/recipes/users/4177048/http://code.activestate.com/recipes/577578-calculate-pi-using-monte-carlo-simulations-in-pyth/ <p style="color: grey"> Python recipe 577578 by <a href="/recipes/users/4177048/">Zach Pace</a> (<a href="/recipes/tags/calculate/">calculate</a>, <a href="/recipes/tags/carlo/">carlo</a>, <a href="/recipes/tags/monte/">monte</a>, <a href="/recipes/tags/pi/">pi</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>I saw something like this in C++ as an introduction to Monte Carlo, so I decided to make something similar in Python. My original code used for loops, but I vectorized it with no small amount of effort, and it now runs orders of magnitude faster. For example, I can calculate pi to .002% error with 100,000,000 randomized coordinates in approximately 15 seconds. Careful to start small, because memory fills up quickly, and the computer will run slow if you overstep your RAM. I'm able to go up to a bit more than 150 million without compromising speed and functionality in other tasks.</p> <p>For those who are curious, vectorization is a technique whereby numpy (or similar) arrays replace things like loops. They're a bit tricky to write (at least for me), but they work beautifully.</p> <p>It might be useful for visualization to plot the occurrence of data points, and observe the randomness</p>