[Tutor] While Loops: Coin Flip Game :p:

Dave Angel davea at ieee.org
Tue Nov 16 08:55:09 CET 2010


> When I run this code (I'm also a noob) I get this result:-
>
>>>> [evaluate lines 1-22 from untitled-1.py]
> The number of heads was 73
> The number of tails was 100
>
> Press the enter key to exit.
>
> # Surely, if flipping a single coin 100 times your total number of heads and
> tails should add up to 100
> # not 173 or am I missing the point?
>
>
No, you're missing an indentation.  If you check the code you're 
running, I think you'll find that you didn't unindent the line 
incrementing count.

Of course, it's less error prone to simply use
for count in xrange(100):

instead of while count < 100:

and you wouldn't need to increment count.

DaveA



More information about the Tutor mailing list