Skip to content

Instantly share code, notes, and snippets.

@dwin
Created December 24, 2016 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwin/a98218f9b78eb2aca4f163aca7c6d88c to your computer and use it in GitHub Desktop.
Save dwin/a98218f9b78eb2aca4f163aca7c6d88c to your computer and use it in GitHub Desktop.
Basic Coin Toss in Python
import random
heads = 0
tails = 0
def flipResult():
random_num = random.random()
rounded = round(random_num)
if rounded == 0:
return 0
else:
return 1
for count in range(1,5001):
result = ''
if flipResult() == 0:
heads += 1
result = 'Head!...'
else:
tails += 1
result = "Tail!..."
print "Attempt #:", count , "Throwing a coin!.... It's a", result, "So far there are:", tails, "tail(s) and", heads , "head(s)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment