I am running some code for a class and I have no clue what to do, I submitted the assignment but it's not helpful if I don't know what to do in the end. Here is the code that I am running to try and track these tests. The idea is to see how many children it takes before you have at least 1 child of each sex. Then the program should be storing that to a list value as boysandgirls_stats[x]. The problem is that it won't store all tests. It only logs around 40 out of 100 or 200 out of 1000. I don't know where these other tests are being stored. stdarray is something we have to use from a book we are using. It tracks the tests similarly to how a list would in python but it wasn't explained well to me. Thank you!
import stdio
import random
import sys
import stdarray
numTrials = int(sys.argv[1])
boysandgirls_stats = stdarray.create1D(4, 0)
boys = 0
girls = 0
children = 0
totalChildren = 0
for x in range(numTrials): # Simulation to determine sex
childType = random.randint(0, 1)
if childType == 0:
boys += 1
children += 1
totalChildren += 1
else:
girls += 1
children += 1
totalChildren += 1
for x in range(numTrials): # Keeps track of amount of children needed
if (boys >= 1) and (girls >= 1):
if children <= 5:
boysandgirls_stats[children - 2] += 1
boys = 0
girls = 0
children = 0
else:
boysandgirls_stats[3] += 1
boys = 0
girls = 0
children = 0
avgChildren = totalChildren / numTrials # Calculation for average children
stdio.writeln('Avg # of children: ' + str(avgChildren))
for x in range(len(boysandgirls_stats)):
stdio.writeln(str(x+2) + ' children ' + str(boysandgirls_stats[x]))