[Tutor] Problem with a while loop.

. , administrata at hotmail.com
Tue May 17 22:12:18 CEST 2005


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/



More information about the Tutor mailing list