Flip 100 Coins (Heads Or Tails)

By AnaBotNowYourGone on Jun 05, 2010

A very simple thing I created. Just copy and paste the code and you're good to go!

import random

tails = 0
heads = 0
flip = 0

while flip < 100:
    fliparoo = random.randrange(2)
    if fliparoo == 0:
        tails = tails + 1
    else:
        heads = heads + 1
    flip += 1

print "There were 100 coins and you flipped them all! " + str(tails) + " were tails and " + \
    str(heads) + " were heads, thanks for flipping! "

Comments

Sign in to comment.
colinmcc   -  Jan 20, 2011

Update for python3... Add () to the print statement..

Eg:
print ("There were 100 coins and you flipped them all! " + str(tails) + " were tails and " + \
str(heads) + " were heads, thanks for flipping! ")

 Respond  
Callum Carolan   -  Oct 10, 2010

Using a variable for the number of coins would have been better

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.