[Tutor] Loop

Vincent Balmori vincentbalmori at yahoo.com
Sun Jun 5 00:03:32 CEST 2011


Hello. Right now I am learning the python language through Python Programming 
for the Absolute Beginner 3rd Edition. I am having trouble with one question in 
Ch. 3 #2, which says "Write a program that flips a coin 100 times and then tells 
you the number of heads and tails." Right now I am having trouble connecting the 
random.randint function into the loop.


# Coin

import random

# Set up Values

coin = random.randint(1,2)
tails = 0
heads = 0
if (coin == 1):
    tails += 1
else:
    heads += 1

toss = 0
while toss < 100:
    toss += 1
    coin = input(random.randint(1,2)


print("Toss Count:", count)
print("Tails:", tails)
print("Heads:", heads)

input("\n\nPress the enter key to exit.")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110604/638b551e/attachment.html>


More information about the Tutor mailing list