[Tutor] while/if/elif/else loops
Norman Silverstone
norman at littletank.org
Tue Nov 1 11:37:58 CET 2005
> #Coin Toss Game
>
> print "This game will simulate 100 coin tosses and then tell you the
> number of head's and tails"
>
> import random
>
> tosses = 0
> heads = 0
> tails = 0
>
> while tosses = 100<0:
> coin = randrange(1)
> tosses +=1
> if coin == 0:
> heads +=1
> print "Heads"
> else:
> tails +=1
> Print "Tails"
This problem was covered only a few days ago and I suggest the replies
are looked up. Incidentally coin = random.randrange(1) can surely only
return 0 and, if one is to look at a random result between heads and
tails then coin should = random.randrange(2).
Norman
More information about the Tutor
mailing list