import random def pi_estimate(n, seed=0): random.seed(seed) n_inside = 0 for i in range(n): if random.random()**2 + random.random()**2 < 1: n_inside += 1 return 4 * (n_inside / n)
- import random
def PiEstimate(runs):random.seed(0)inner = 0- def pi_estimate(n, seed=0):
- random.seed(seed)
- n_inside = 0
- for i in range(n):
- if random.random()**2 + random.random()**2 < 1:
inner += 1return 4 * (inner / n)- n_inside += 1
- return 4 * (n_inside / n)
# TODO: Replace examples and use TDD development by writing your own tests # These are some of the methods available: # test.expect(boolean, [optional] message) # test.assert_equals(100000, 3.14844) # test.assert_equals(1000000, 3.14244) test.assert_equals(pi_estimate(1000, seed=42), 3.128) test.assert_equals(pi_estimate(1000000, seed=42), 3.140592) # You can use Test.describe and Test.it to write BDD style test groupings
- # TODO: Replace examples and use TDD development by writing your own tests
- # These are some of the methods available:
- # test.expect(boolean, [optional] message)
- # test.assert_equals(100000, 3.14844)
- # test.assert_equals(1000000, 3.14244)
test.assert_not_equals(2000000, 3.141634)- test.assert_equals(pi_estimate(1000, seed=42), 3.128)
- test.assert_equals(pi_estimate(1000000, seed=42), 3.140592)
- # You can use Test.describe and Test.it to write BDD style test groupings