Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- s = input("Please enter the number of simulations you want: ")
- if s.isdigit() and int(s)>0:
- flips = []
- for i in range(int(s)):
- toss = []
- while True:
- if randint(1,2) == 1:
- toss.append("H")
- else:
- toss.append("T")
- if len(toss) >=3 and toss[-1] == toss[-2] == toss[-3]:
- break
- display = ""
- for t in toss:
- display += t
- display += " "
- print(display)
- flips.append(len(toss))
- print(f'The average number of flips are {sum(flips)/int(s)}')
- print(f'The maximum number of flips made to get three in row is {max(flips)}')
- 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