[Tutor] Coin Flip

taserian taserian at gmail.com
Fri Oct 3 20:26:47 CEST 2008


Since the variable *count* never increases inside of the loop body, it gets
stuck in the *while* loop.

I recommend taking a hard look at the program, consider what it should be
doing, and then seeing which statements should be in the *while* loop, and
which ones should be outside it.

Tony R.

On Fri, Oct 3, 2008 at 2:04 PM, realNewbie <dilisamom at yahoo.com> wrote:

>
> This is a class assignment, I am to create a program that flips a coin 100
> times and tells me the number of heads and tails.
> I've been working on it for 2 days now and I am stuck. I a trying to run
> the
> program but it is not running.
> Can someone please point out my error?
>
> Here is what I have come up with:
> import random
> heads=0
> tails=0
> count=1
> while count <101:
>   randomFlip = random.randrange(0,1)
> if randomFlip == 0:
>    heads = heads + 1
> else:
>    tails = tails + 1
> count = count + 1
> print heads," heads"
> print tails," tails"
> --
> View this message in context:
> http://www.nabble.com/Coin-Flip-tp19802888p19802888.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081003/08c50df2/attachment.htm>


More information about the Tutor mailing list