Dear Tutors,<br><br>I have an assignment for class due in about 6 hours and I&#39;ve been working on it for about 3 hours already, getting nowhere.<br><br>My assignment is as follows:<br><br><p style="margin-left: 40px;" class="MsoNormal">
<font size="1">I</font><font size="1">n this exercise, you will write several functions and use
them in different ways.<span>  </span>Follow the specifications;
I insist.</font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1"> </font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1">First, write a function that simulates flipping a coin.<span>  </span>This function needs no parameters.<span>  </span>When called, it should return either “HEADS”
or “TAILS”.<span>  </span>Those are strings. <span>  </span>That’s <u>return</u>, not print.</font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1"> </font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1">When that function is working, write another function to
exercise it.<span>  </span>This function should have
one parameter, a positive number.<span>  </span>This
function will call the previous function that number of times, and count the
number of heads.<span>  </span>When finished, it should
<u>return</u> (not print) the number of heads.</font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1"> </font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1">Now, write code to test it.<span> 
</span>I want you to try three times.<span> 
</span>There are three well-known experiments that I want you to replicate:</font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1"> </font></p>

<p class="MsoNormal" style="margin-left: 0.7134in;"><font size="1">The French naturalist Count <span class="SpellE">Buffon</span> (1707-1788) tossed a coin 4040 times. Results: 2048
heads, or proportion 2048/4040 = 0.5069 for heads.</font></p>

<p class="MsoNormal" style="margin-left: 0.7134in;"><font size="1"><br>
Around 1900, the English statistician Karl Pearson tossed a coin 24,000 times.
Result: 12,012 heads, a proportion of 0.5005.<br><br></font>

</p>

<p class="MsoNormal" style="margin-left: 0.7134in;"><font size="1">While imprisoned by the Germans
during World War II, the South African mathematician John <span class="SpellE">Kerrich</span>
tossed a coin 10,000 times. Result: 5067 heads, a proportion of 0.5067.</font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1"> </font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1">For each of these, print out enough to explain the result,
not just a number.</font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1"> </font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1"> </font></p>

<p style="margin-left: 40px;" class="MsoNormal"><font size="1">One more thing to do:<span> 
</span>run the Pearson experiment 24000 times.<span> 
</span>Report the number of times that the count of heads exceeds the number of
tails.</font></p><br><br>I have gotten a few steps in with my programming, and have completed this, which will give me heads / tails for as many times as I want. However, it just lists either &quot;Heads&quot; or &quot;Tails in a column.  <br>
<br style="color: rgb(0, 102, 0);"><div style="margin-left: 40px;"><span style="color: rgb(0, 102, 0);">import random</span><br style="color: rgb(0, 102, 0);"><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);">def coinToss():</span><br style="color: rgb(0, 102, 0);">
<span style="color: rgb(0, 102, 0);">    </span><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);">    flip = random.randrange(2)</span><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);">    if flip == 0:</span><br style="color: rgb(0, 102, 0);">
<span style="color: rgb(0, 102, 0);">        return &quot;Heads&quot;</span><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);">    else:</span><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);">        return &quot;Tails&quot;</span><br style="color: rgb(0, 102, 0);">
<br style="color: rgb(0, 102, 0);"><br style="color: rgb(0, 102, 0);"><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);">def multicoinToss(tosses):</span><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);">    for i in range(tosses):</span><br style="color: rgb(0, 102, 0);">
<span style="color: rgb(0, 102, 0);">        print (coinToss())</span><br style="color: rgb(0, 102, 0);"><br style="color: rgb(0, 102, 0);"><span style="color: rgb(0, 102, 0);">print (multicoinToss(20))</span><br><br><br>
</div>However, no matter how many ways I try to alter my code, I just can&#39;t work in some way or some accumulator pattern to add up my number of heads or tails!<br>Can anybody help me figure out how to do it?  I&#39;ve found codes that work with accumulator coin tosses, but they are based on a preset number of tosses and have nothing to do with returns, etc. in them.  <br>
<br>Gah, I hope somebody here can help save me.  :(<br><br clear="all"><br>-- <br>Colleen Glaeser<br><a href="mailto:songbird42371@gmail.com">songbird42371@gmail.com</a> <br>636.357.8519<br>