12.5. Building a Simulation - 2¶
Now that we have a working function, we can focus on using the function. Look for the spot
with missing code at line 28. Add the needed code to complete the accumulator pattern to
count up the number of times
result ends up as
True. The expected answer is around
80% - about 8 times out of 10 you should get at least 5 heads in a row if you flip a coin
If you run into troubles, here are some debugging tips:
checkHeadsInRowworks. Focus your attention on the main part of the program.
resultyou get in each repetition loop.
successCounterat the end of each repetition of the loop.
Reduce repetitions to something like 10 to make it easier to see all the output. Your answer will be less reliable with fewer repetitions, so reset it to 10000 when you are done debugging.