Created
April 23, 2012 20:36
-
-
Save anonymous/2473672 to your computer and use it in GitHub Desktop.
cointoss
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 | |
import sys | |
def main(): | |
class test: | |
number_given = 1 | |
while number_given != 0: | |
number = input('Enter the number of times you want the coin to be flipped: ') | |
number_given = number | |
if number > 0: | |
tails = 0 | |
heads = 0 | |
for count in range(number): | |
coin_toss = random.randint(0,1) | |
if coin_toss == 0: | |
print "tails" | |
tails += 1 | |
else: | |
print "heads" | |
heads += 1 | |
print("You flipped %d heads and %d tails." % (heads, tails)) | |
else: | |
sys.exit() | |
test() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment