Advertisement
biswasrohit20

flip

Mar 24th, 2021
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. from random import randint
  2.  
  3. s = input("Please enter the number of simulations you want: ")
  4. if s.isdigit() and int(s)>0:
  5. flips = []
  6. for i in range(int(s)):
  7. toss = []
  8. while True:
  9. if randint(1,2) == 1:
  10. toss.append("H")
  11. else:
  12. toss.append("T")
  13. if len(toss) >=3 and toss[-1] == toss[-2] == toss[-3]:
  14. break
  15. display = ""
  16. for t in toss:
  17. display += t
  18. display += " "
  19. print(display)
  20. flips.append(len(toss))
  21. print(f'The average number of flips are {sum(flips)/int(s)}')
  22. print(f'The maximum number of flips made to get three in row is {max(flips)}')
  23. print(f'The minimum number of flips made to get three in row is {min(flips)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement