So I have this exercise to do:
Write a program to find out how often a streak of six heads or a streak of six tails comes up in a randomly generated list of head and tails and if there is a streak you add to to the variable number_of_streaks
I made the loop for adding H and T to the list but I don't know how to check if there is a streak in that list. I tried this code:
if th[experiment_number][z] == th[experiment_number][z+1]:
but I get this error:
IndexError: string index out of range
(Note I am new to programming, I am still learning)
import random
number_of_streaks = 0
th = []
for experiment_number in range(10000):
for x in range(100):
if random.randint(0, 1):
th.append('H')
else:
th.append('T')
first = 0
last = 5
for x in range(100):
for z in range (6):
if th[experiment_number][z] == th[experiment_number][z+1]:
number_of_streaks += 1