Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Created February 15, 2012 15:38
Show Gist options
  • Select an option

  • Save ChrisMoney/d6c6b5c7de3ed829bacc to your computer and use it in GitHub Desktop.

Select an option

Save ChrisMoney/d6c6b5c7de3ed829bacc to your computer and use it in GitHub Desktop.
Python --Coin Toss Program
//Coin Toss Program
import random
headcount = tailcount = 0
userinput = ' '
print "Now tossing a coin.."
while userinput.lower() ! = "q":
flip = random.choice(['heads', 'tails'])
if flip == 'heads' :
headcount += 1
print "heads! the number of heads is now %d" % headcount
else:
tailcount + = 1
print "tails! the number of tails is now %d" % tailcount
userinput = raw_input("or another key to toss again:")
print "the total number of heads:", headcount
print "the total number of tails: ", tailcount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment