Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modeling the Dynamics of Life Calculus and Probability for Life Scientists

Authors: Frederick R. Adler

3rd edition

840064187, 978-1285225975, 128522597X, 978-0840064189

More Books

Students also viewed these Programming questions