import random
numStreaks = 0
for experimentNum in range(10000):
# Code that creates a list of 100 'heads' or 'tails' values.
outcome = []
for i in range(100):
if random.randint(0,1) == 0:
outcome.append('H')
else:
outcome.append('T')
# Code that checks if there is a streak of 6 heads or tails in a row
Hstreak = 0
for i in range(len(outcome)):
for x in range(6):
if outcome[x] == 'H':
Hstreak += 1
if Hstreak == 6:
numStreaks += 1
else:
numStreaks = 0
print ('Chance of streak: %s%%' % (numStreaks/100))
I'm having trouble with the coin flip project from chapter 4. I have no idea on what I'm missing or doing wrong. I tried to run the code, but nothing comes up. I've looked up other people's takes on the project, but I still have no clue why my code doesn't work.
In your
you're setting
numStreaksto 0 every timeHStreakis not 6.