Question: Create a python program that uses a random number generator to simulate flipping a coin several times. The simulated coin should be fair, meaning
Create a python program that uses a random number generator to simulate flipping a coin several times. The simulated coin should be fair, meaning that the probability of heads is equal to the probability of tails. Your program should flip simulated coins until either 3 consecutive heads of 3 consecutive tails occur. Display a H each time the outcome is heads, and a T each time the outcome is tails, with all of the outcomes shown on the same line. Then display the number of flips needed to reach 3 consecutive flips with the same outcome. When your program is run it should perform the simulation 10 times and report the average number of flips needed. Use functions in your solution. Sample output is shown below: HTTT (4 flips) (19 flips) TTT (3 flips) TH H H (4 flips) HHH (3 flips) THT THTH HTTHHTHTH H H (18 flips) HTTHHH (6 flips). THTTT (5 flips) TTHT THTHTHHH (12 flips) THTTT (5 flips) On average, 7.9 flips were needed. Hint: To print on the same line, use the below technique. for i in range (4): print (i, end" ") Output: 0 1 2 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
