Skip to content

Instantly share code, notes, and snippets.

@unacceptable
Last active January 22, 2021 07:07
Show Gist options
  • Save unacceptable/a3663db71eb80cf56fc605a0735d3094 to your computer and use it in GitHub Desktop.
Save unacceptable/a3663db71eb80cf56fc605a0735d3094 to your computer and use it in GitHub Desktop.
#!/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