Question: Coin Flip Streaks For this exercise, well try doing an experiment. If you flip a coin 100 times and write down an H for each
Coin Flip Streaks
For this exercise, well try doing an experiment. If you flip a coin 100 times and write down an H for each heads and T for each tails, youll create a list that looks like T T T T H H H H T T. If you ask a human to make up 100 random coin flips, youll probably end up with alternating head-tail results like H T H T H H T H T T, which looks random (to humans), but isnt mathematically random. A human will almost never write down a streak of six heads or six tails in a row, even though it is highly likely to happen in truly random coin flips. Humans are predictably bad at being random. 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 heads and tails. Your program breaks up the experiment into two parts: the first part generates a list of randomly selected 'heads' and 'tails' values, stored in a list, and the second part determines the longest streak of heads. Put all of this code in a loop that repeats the experiment 10,000 times so we can find out what the longest streak of heads is, as well as the total number of heads an tails. As a hint, the function call random.randint(0, 1) will return a 0 value 50% of the time and a 1 value the other 50% of the time. You can start with the following template: import random myStreak = 0 # Code that creates a list of 10000 'heads' or 'tails' values. for i in range(10000): # Code that finds the longest streak of heads in a row. #output print('Longest streak: ' + str(myStreak)) print("Number of heads: " + str(numHeads) + " Number of tails: " + str(numTails))
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
