Machine Learning, Data Science.
0 for _ in range(samples): x = random.random() y = random.random() if math.sqrt((x ** 2) + (y ** 2)) < 1: hits += 1 ratio = (float(hits) / samples) * 4 print('Estimate with {0} samples: {1}'.format(samples, ratio)) Let’s try it out with varying numbers of samples and see what happens.