Guest User

Untitled

a guest
Jun 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. def contain_ellipse(x, y):
  2. return x*x + y*y + x*y - 1
  3.  
  4. import random
  5.  
  6. count = 0.0
  7. total = 0.0
  8. area = 9.0
  9. while (count < 1000000):
  10. count = count + 1
  11. x = random.uniform(-1.5, 1.5)
  12. y = random.uniform(-1.5, 1.5)
  13. f = contain_ellipse(x, y)
  14. if (f < 0):
  15. total = total + 1
  16. percentage = total / count
  17. print percentage
  18. approximation = percentage * area
  19. print approximation
Add Comment
Please, Sign In to add comment