Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import random
- def main():
- trials = 1000000
- sets = []
- for i in range(trials):
- a = 0 # first (eldest) child is always a girl
- b = random.randrange(2) # parents have second child (coinflip)
- sets.append((a, b))
- num_boys = 0 # number of times the edlest's sibling is a boy
- num_girls = 0 # number of times the edlest's sibling is a girl
- for s in sets:
- if s[1] == 1: # sibling is a boy
- num_boys += 1
- else:
- num_girls += 1
- print ("Number of times sibling is a boy: %d" % num_boys)
- print ("Number of times sibling is a girl: %d" % num_girls)
- print ("Probability of sibling being a boy: %.2f%%" % (num_boys / (num_boys + num_girls) * 100))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement