Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- total_births = []
- def give_birth():
- return random.choice(['G', 'B'])
- def give_birth_until_boy():
- baby = give_birth()
- family_births = [baby]
- while (baby == 'G'):
- baby = give_birth()
- family_births.append(baby)
- return family_births
- def printCount(n, births):
- boyCount, girlCount = births.count('B'), births.count('G')
- print(f"n = {n}\t\tboys = {boyCount}\t\tgirls {girlCount}")
- def simulate_families(n):
- for i in range(n):
- family_babies = give_birth_until_boy()
- total_births.extend(family_babies)
- printCount(n, family_babies)
- printCount('all', total_births)
- simulate_families(100000)
Advertisement
Add Comment
Please, Sign In to add comment