Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def coinflip():
- return random.choice((True, False))
- kids = {'Girl': 0, 'Boy': 0}
- brothers = {'Girl': 0, 'Boy': 0}
- for _ in range(1000000):
- boy_count = 0
- family = []
- for _ in iter(coinflip, False):
- kid = random.choice(('Girl', 'Boy'))
- family.append(kid)
- if kid == 'Boy':
- boy_count += 1
- for kid in family:
- kids[kid] += 1
- brothers[kid] += boy_count - int(kid == 'Boy')
- print('Out of a sample of', kids['Girl'], 'girls, and', kids['Boy'], 'boys:')
- print('The average girl has', brothers['Girl']/kids['Girl'], 'brothers.')
- print('The average boy has', brothers['Boy']/kids['Boy'], 'brothers.')
- print('Ratio:', (brothers['Girl']/kids['Girl'])/(brothers['Boy']/kids['Boy']))
Advertisement
Add Comment
Please, Sign In to add comment