Advertisement
gregwa

FCM 158 - Cointoss.py

Jun 3rd, 2020
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #! /usr/bin/env python
  2. #  -*- coding: utf-8 -*-
  3. # ======================================================
  4. #     cointoss.py
  5. #  ------------------------------------------------------
  6. # Created for Full Circle Magazine Issue #158 June 2020
  7. # Written by G.D. Walters
  8. # Copyright (c) 2020 by G.D. Walters
  9. # This source code is released under the MIT License
  10. # ======================================================
  11. from numpy.random import seed
  12. from numpy.random import randint
  13. # seed random number generator
  14. seed(1)
  15. # "flip" 10 times and do it twice.
  16. # todo = 100000000
  17. todo = 10
  18. loops = 2
  19. for loop in range(loops):
  20.     flips = randint(0, 2, todo)
  21.     print(flips)
  22.     heads = 0
  23.     tails = 0
  24.     for flip in flips:
  25.         if flip == 0:
  26.             tails += 1
  27.         else:
  28.             heads += 1
  29.  
  30.     print(f'Heads: {heads} - Tails: {tails}')
  31.     pctHeads = (heads/todo) * 100
  32.     print(f'Percentage of Heads: {pctHeads}%')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement