title: Python - Probability of 6 or more Tails/Heads Code
body: <p>I assigned my students in comp sci to write a code that simulates flipping a coin 100 times, storing the results in a list. Look for a streak of 6 heads ( or more ), or 6 tails ( or more ). If you find a streak, then consider the trial a success. Repeat this experiment 10,000 times. Use this to determine the probability of finding a streak of 6 heads or 6 tails.</p>
  <p>Theoretically this probability should be ~80%.</p>
  <p>EDIT: It is possible I misinterpreted this theoretical probability. I found this probability here: <a href="https://math.stackexchange.com/questions/2736117/what-is-the-probability-of-getting-6-or-more-heads-or-tails-in-a-row-after-flipp">https://math.stackexchange.com/questions/2736117/what-is-the-probability-of-getting-6-or-more-heads-or-tails-in-a-row-after-flipp</a></p>
  <p>My code is giving me a probability of about 54%, the probability of getting exactly 6 in a row. However, if I got 7, 8, 9, or more in a row, my code should mark this as a success, correct?</p>
  <p>I understand my code checks for steaks of 6, but if there is a streak of 7, 8, 9, ... it would still mark it as a success. There must be something I'm missing here...</p>
  <p>Attached is my code:</p>
  <pre><code>import random
  numberofstreaks = 0
  for experimentnumber in range(10000):
      result = []
      for i in range(100):
          flip = random.randint(0,1)
          result.append(flip)
      
      for i in range(len(result)-6):
          if result[i:i+6] == ([0,0,0,0,0,0] or [1,1,1,1,1,1]):
              numberofstreaks += 1
              break
  print(numberofstreaks)
  print('Chance of steak:',(numberofstreaks/100))
  </code></pre>
  <p>Note: They are currently learning about lists, which is why their code must contain the use of lists.</p>
  <p>Thanks ahead of time!</p>