import random

head = 0
tail = 0

while (head + tail) < 100:
    coin = random.randrange(2)  <-- move this line inside the loop
    if coin == 0: 



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of . ,
Sent: Tuesday, May 17, 2005 4:12 PM
To: [email protected]
Subject: [Tutor] Problem with a while loop.

Hi,

I'm writing a program that is a program that flips a coin 100 times and
then tells the number of heads and tails.

------------------------------------------------------------------------
-------------------------------------------------------------------

import random

head = 0
tail = 0
coin = random.randrange(2)

while (head + tail) < 100:
    if coin == 0:
        print "head"
        head += 1

    elif coin == 1:
        print "tail"
        tail += 1

    else:
        print "Error"


raw_input("")

------------------------------------------------------------------------
-------------------------------------------------------------------

The problem is the program prints like..
tail
tail
tail
.
.
.

Help me!

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! 
http://search.msn.com/

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to