python snippet for calculating child numbers