Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import shuffle
- def cointoss(n):
- h, t = 'H', 'T'
- SampleS = [h*n, t*n]
- if n == 1:
- print(SampleS)
- else:
- L1 = list(h*n)+list(t*n)
- while True:
- shuffle(L1)
- event = L1[:n]
- str1 = ''
- for i in event:
- str1 += i
- else:
- if str1 not in SampleS:
- SampleS.append(str1)
- str1 = ''
- else:
- continue
- if len(SampleS) == 2**n:
- break
- SampleS.sort()
- for i in ('H','T'):
- for j in SampleS:
- if i == j[0]:
- print(j, end=", ")
- else:
- print()
- cointoss(4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement