When I run this code (I'm also a noob) I get this result:-<div><div><br></div><div>>>> [evaluate lines 1-22 from untitled-1.py]</div><div>The number of heads was 73</div><div>The number of tails was 100</div><div>
<br></div><div>Press the enter key to exit.</div><div><br></div><div># Surely, if flipping a single coin 100 times your total number of heads and tails should add up to 100</div><div># not 173 or am I missing the point?</div>
<div><br></div><div><br></div><br><div class="gmail_quote">On 16 November 2010 15:08, Nithya Nisha <span dir="ltr"><<a href="mailto:nithyakarpagam@gmail.com">nithyakarpagam@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Tom,<br><br>Your code is almost correct. Little mistake is there.The random number generate should be in while loop.<br><br>> import random<br>
><br>
> # set the coin<br>
<br>
> headsCount = 0<br>
> tailsCount = 0<br>
> count = 0<br>
><br>
> # the loop<br>
> while count < 100: #If you declare count = 0. The while loop condition should be less than 100.Else you will get 101 counts.<br>
> <b>coin = random.randrange(2)</b><br>> if coin == 0:<br>
> headsCount += 1<br>
> else: #Becase We already declared randrange(2).So the coin value is 0 or 1.So we can use else condition.<br>
> tailsCount += 1<br>
> count += 1<br>
><br>
><br>
> print "The number of heads was", headsCount<br>
> print "The number of tails was", tailsCount<br>
><br>
> raw_input("\n\nPress the enter key to exit.")<br><br><div class="gmail_quote">Regards,<br>Nithya<br><br>_____________________________________________________________________________________________________________________________________________________________<br>
<b><br>Your Description</b>:<br><br>On Mon, Nov 15, 2010 at 7:19 AM, Thomas C. Hicks <span dir="ltr"><<a href="mailto:paradox@pobox.com" target="_blank">paradox@pobox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204);margin:0pt 0pt 0pt 0.8ex;padding-left:1ex">
On Sun, 14 Nov 2010 17:16:36 -0500<br>
Dawn Samson <<a href="mailto:sdawn@live.ca" target="_blank">sdawn@live.ca</a>> wrote:<br>
<br>
> Greetings,<br>
><br>
> I'm a Python beginner and working my way through Michael Dawson's<br>
> Python Programming for the Absolute Beginner. I'm stuck in a<br>
> particular challenge that asks me to write a program that "flips a<br>
> coin 100 times and then tells you the number of heads and tails."<br>
> I've been trying to work on this challenge for a while now and can't<br>
> get it to work (either it has 100 heads or 100 tails). I've been<br>
> reworking this code many times and currently what I have does not do<br>
> anything at all at IDLE. Please take a look at my code below:<br>
><br>
> import random<br>
><br>
> # set the coin<br>
> coin = random.randrange(2)<br>
> headsCount = 0<br>
> tailsCount = 0<br>
> count = 0<br>
><br>
> # the loop<br>
> while count <= 100:<br>
> coin<br>
> if coin == 0:<br>
> headsCount += 1<br>
> if coin == 1:<br>
> tailsCount += 1<br>
> count += 1<br>
><br>
><br>
> print "The number of heads was", heads<br>
> print "The number of tails was", tails<br>
><br>
> raw_input("\n\nPress the enter key to exit.")<br>
><br>
> Thanks,<br>
> S. Dawn Samson<br>
<br>
>From one beginner to another - it looks to me like you set the value of<br>
coin once then checked it 100 times. If you want to reset the value of<br>
coin maybe it (i.e. setting the value of coin, not just calling<br>
the value of coin) should be in the loop too?<br>
<br>
tom<br>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</blockquote></div><br><br>
<br>_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Luke Pettit<br>
</div>