A common requirement that we have when performing statistical analysis is to compute basic means, modes, and standard deviations on a collection of data. Our blackjack simulation will produce outcomes that must be analyzed statistically to see if we have actually invented a better strategy.
When we simulate the playing strategy for a game, we will develop some outcome data that will be a sequence of numbers that show the final result of playing the game several times with a given strategy.
We could accumulate the outcomes into a built-in list class. We can compute the mean via , where is the number of elements in :
def mean(outcomes: List[float]) -> float:
return sum(outcomes) / len(outcomes)
Standard deviation can be computed via :
def stdev(outcomes: List[float]) -> float:
n = float(len(outcomes))
return math.sqrt(
n ...