Last active
January 22, 2021 07:07
-
-
Save unacceptable/a3663db71eb80cf56fc605a0735d3094 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
import sys | |
import random | |
def main(flips): | |
print('Flipping {} times.'.format(flips)) | |
count = 0 | |
for i in range(flips): | |
count += flip() | |
print('{} %'.format(float(count)/flips*100)) | |
def flip(): | |
if bool(random.getrandbits(1)): | |
return 1 | |
return 0 | |
# python flip.py 10 | |
# python flip.py 159 | |
# python flip.py 19502 | |
# python flip.py 10000000 | |
main(flips=int(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment