Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- TotalHeadStreaks = 0
- TotalTailStreaks = 0
- CommonStreak = 0
- for i in range(1000):
- tosses=[]
- for j in range(100):
- toss = randint(0,1)
- if toss == 1:
- tosses.append('H')
- else:
- tosses.append('T')
- for k in range(95):
- if tosses[k]=='H' and tosses[k+1]=='H' and tosses[k+2]=='H' and tosses[k+3]=='H' and tosses[k+4]=='H' and tosses[k+5]=='H':
- TotalHeadStreaks += 0.01
- if k < 89:
- if tosses[k+6]=='T' and tosses[k+7]=='T' and tosses[k+8]=='T' and tosses[k+9]=='T' and tosses[k+10]=='T' and tosses[k+11]=='T':
- TotalTailStreaks += 0.01
- CommonStreak += 0.01
- elif tosses[k]=='T' and tosses[k+1]=='T' and tosses[k+2]=='T' and tosses[k+3]=='T' and tosses[k+4]=='T' and tosses[k+5]=='T':
- TotalTailStreaks += 0.01
- if k < 89:
- if tosses[k+6]=='H' and tosses[k+7]=='H' and tosses[k+8]=='H' and tosses[k+9]=='H' and tosses[k+10]=='H' and tosses[k+11]=='H':
- TotalHeadStreaks += 0.01
- CommonStreak += 0.01
- StreakProbability = round(((TotalHeadStreaks + TotalTailStreaks - CommonStreak)/1000), 2)
- print(f"The Probability of either getting 6 Heads Continuously or 6 Tails Continuously : {StreakProbability}")
Add Comment
Please, Sign In to add comment