Created
December 24, 2016 01:47
-
-
Save dwin/a98218f9b78eb2aca4f163aca7c6d88c to your computer and use it in GitHub Desktop.
Basic Coin Toss in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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