Created
April 4, 2019 01:55
-
-
Save 3735943886/c3cd83fa1867e2b6f227d16e2f632200 to your computer and use it in GitHub Desktop.
Sex ratio calculation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import random | |
CONST_FAMILIES = 65536 | |
CONST_GENERATIONS = 100 | |
CONST_NATURAL_RATIO = 0.5 | |
# User input data | |
A1 = input('How many families are there? (default ' + str(CONST_FAMILIES) + ')') | |
A2 = input('How many children will one family have? (default ' + str(CONST_GENERATIONS) + ')') | |
# Data processing | |
try: | |
families = int(A1) | |
except: | |
families = CONST_FAMILIES | |
try: | |
generations = int(A2) | |
except: | |
generations = CONST_GENERATIONS | |
# Total number of boys and girls | |
totalboys = 0 | |
totalgirls = 0 | |
# Loop | |
for i in range(0, generations): | |
# Number of boys in current generations | |
boys = 0 | |
for j in range(0, families): | |
childsex = int(random() + CONST_NATURAL_RATIO) | |
boys += childsex | |
print('{0} - total {1}, M/F ratio : {2}/{3}'.format(i + 1, families, boys, families - boys)) | |
totalboys += boys | |
totalgirls += families - boys | |
# Only families who gave birth a boy will be calculated next loop | |
families = boys | |
if(boys == 0): | |
break | |
print('total children : {0}, boys : {1}, girls {2}'.format(totalboys + totalgirls, totalboys, totalgirls)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, ever had one of those nights where you're just bored and want some excitement? That was me a few weeks ago. I kept seeing people talk about www.flirtini.com/local.html, so I gave it a go. I was expecting endless small talk, but nope—people here actually know what they want. Matched with someone who had the same energy, and let’s just say, that night was anything but boring.