[Tutor] Random in loop

ZIYAD A. M. AL-BATLY zamb at saudi.net.sa
Sun Jan 15 03:10:07 CET 2006


On Sat, 2006-01-14 at 17:52 -0800, ryan luna wrote:
> Hello, Im kinda stuck on something in the book Python
> Programming.
> The "Challenage" is to make a progam that flips a coin
> 100 times and then tells you the number of heads and
> tails.
> here is what i have so far,
> Code:
> 
> import random
> 
> coin = 0
> heads = 0
> tails = 0
> 
> heads_tails = random.randrange(2)
Why is the above line outside the loop?  Shouldn't you be flipping it a
100 times?  You're doing it once in this program.  (I think you know by
know what you should do to correct this!)

> while coin < 100:
>     coin += 1
 <snip>


I hope this was helpful.
Ziyad.



More information about the Tutor mailing list