[Tutor] While Loops: Coin Flip Game :p:
Stephanie Dawn Samson
sdawn at live.ca
Tue Nov 16 21:36:34 CET 2010
Greetings,
As a thread starter, I thought I should write the rewritten code I got that others helped me get to, since this thread is still going on.
# Coin Flips# The program flips a coin 100 times and then# tells you the number of heads and tailsimport random
print "\a"print "\tWelcome to 'Coin Flipper!'"print "\nI will flip a coin 100 times and then tell you"print "the number of heads and tails!\n"
# set the coinheadsCount = 0tailsCount = 0count = 1
while count <= 100: coin = random.randrange(2) if coin == 0: headsCount += 1 else: tailsCount += 1 count += 1
print "The number of heads was", headsCountprint "The number of tails was", tailsCount
raw_input("\n\nPress the enter key to exit.")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101116/05191b93/attachment.html>
More information about the Tutor
mailing list