Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def contain_ellipse(x, y):
- return x*x + y*y + x*y - 1
- import random
- count = 0.0
- total = 0.0
- area = 9.0
- while (count < 1000000):
- count = count + 1
- x = random.uniform(-1.5, 1.5)
- y = random.uniform(-1.5, 1.5)
- f = contain_ellipse(x, y)
- if (f < 0):
- total = total + 1
- percentage = total / count
- print percentage
- approximation = percentage * area
- print approximation
Add Comment
Please, Sign In to add comment