Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. from random import random, randint
  2.  
  3. def create_siblings():
  4.     # returns ((Child1, Day1), (Child2, Day2))
  5.     # Child1 is True if first child is male
  6.     # Day1 = 1 -> Monday, 2 -> Tuesday etc
  7.     return ((random() < .5, randint(1, 7)), (random() < .5, randint(1, 7)))
  8.  
  9. girl = 0
  10. boy = 0
  11.  
  12. for i in range(100000000): #100kk simulations
  13.     (c1, d1), (c2, d2) = create_siblings()
  14.     if (c1 and d1==2) or (c2 and d2==2):
  15.         if c1 == c2: # If both children are of the same gender (male)
  16.             boy += 1
  17.         else:
  18.             girl += 1
  19.  
  20. print("{} Boys, {} Girls, {} Ratio".format(boy, girl, boy/(boy+girl)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement