#!/usr/bin/python # # Berechnen von Pi via Monte-Carlo # import random MAX_STEPS = 1e7 step = 0 sum = 0 while step < MAX_STEPS: x = random.random() y = random.random() if x*x + y*y < 1.0: sum = sum + 1 step = step + 1 estimate = 4.0 * sum / MAX_STEPS print 'Abschaetzung fuer pi nach', MAX_STEPS, 'Schritten:', estimate