[Tutor] Basic program question

Alexander Quest redacted@example.com
Sun Jul 24 22:59:38 CEST 2011


Hello- I am running Python v 3.1.1. As an exercise, I wrote a simple coin
flipper program, where the computer flips a coin 100 times and then prints
out the number of heads and tails. My program crashes immediately if I run
it normally through the command line, but if I go to "Run- Run Module," it
seems to work just fine. I can't seem to figure out why. I've pasted the
relevant code below- any help will be greatly appreciated. Thanks!

import random
print("\tWelcome to the 'Coin Flipper' program!")

counter = 0
heads = 0
tails = 0

while counter < 100:
    the_number = random.randint(1, 2)
    if the_number == 1:
        heads += 1
    else:
        tails += 1

    counter += 1

print("\nI flipped the coint 100 times.")
print("It came up heads", heads, "times and tails", tails, "times.")

print("\n\nPress the enter key to exit.")

_________________

-Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110724/959c5d90/attachment.html>


More information about the Tutor mailing list
l>