[Tutor] while/if/elif/else loops
Zameer Manji
zmanji at gmail.com
Mon Oct 31 23:36:35 CET 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
I'm new to programming and python. I've have recently been experimenting
with while/if/elif/else loops and I've created a simple number guessing
game. Now I want to create a coin tossing game, but I don't know how to
structure it in python. The code I already have (but it's not working)
is below.
#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"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
iQEVAwUBQ2accw759sZQuQ1BAQqoyQgAsmVhRidMC1/WpQms6fChX+z62DWSpmRW
qiY9F7bZAYZusyNsHHDUpuTAYdI0LXxgLVmYBKDz3tKhVCbEZTn9FUwgw5A2thYy
I5o82tWXZnIpgmFIN2AysAj2dCI4mSfi/IJjE5JvG+IFELWigMb9Pf6tap4HiB71
IBayql8MN1XrA2zv8fXQs35zVwxnBUSvAHZuUBLi4hDcPxY/d71X/JHqfqpf3svS
ClzUlYqLhXld+39/aiRFKOXHyVCnfsEUcAXB45r110Q3K+7KegwgX4Js8qL5dA66
d74HlLMb6Cp6G5AlNdQoKDin8jlMloxeQpb60hS+HmnBwkEFukyNHA==
=QMuB
-----END PGP SIGNATURE-----
More information about the Tutor
mailing list