Create a python program that uses a random number generator to simulate flipping a coin several...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Modeling the Dynamics of Life Calculus and Probability for Life Scientists
ISBN: 978-0840064189
3rd edition
Authors: Frederick R. Adler
Posted Date:
Students also viewed these programming questions
-
Python and most Python libraries are free to download or use, though many users use Python through a paid service. Paid services help IT organizations manage the risks associated with the use of...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
A population consists of the following N = 5 scores: 0, 6, 4, 3, and 12. a. Compute m and for the population. b. Find the z-score for each score in the population. c. Transform the original...
-
Why does a white piece of paper appear white in white light, red in red light, blue in blue light, and so on for every color?
-
The financial statements of Apple Inc. are presented in Appendix A. Instructions for accessing and using the companys complete annual report, including the notes to the financial statements, are also...
-
A six-cylinder, 4-stroke SI engine delivers \(400 \mathrm{~kW}\) at \(2200 \mathrm{rpm}\). Determine the bore and stroke from the following data : Compression ratio \(=7.6 ;\) stroke to bore ratio...
-
Applin Corporation has a desired rate of return of 8 percent. Troy Anderson is in charge of one of Applins three investment centers. His center controlled operating assets of $5,000,000 that were...
-
An investor bought stock for $40,000. Fifteen years later, the stock was sold for $60,000. If interest is compounded continuously, what annual nominal rate of interest did the original $40,000...
-
Using the information presented in Problem 13.4B, prepare a partial statement of cash flows for the current year, showing the computation of net cash flows from operating activities using the...
-
Question 1 1 When calculating future value the the interest rate the smaller the future value amount Points 3 Question 2 2 interest is interest that is applied a number of times during the term of a...
-
An investor deposits $3000. How long will it take them to double the initial deposit if the investment earns a simple interest rate of 6.0% per annum?
-
Newman has promised to pay all of it retained earnings as dividend in the amount of $12,000 over the next three years and then shut down (plan A). If the required rate of return on its common stock...
-
How can the mining corporations should limit their usage of the FIFO workforce and finding other alternatives solutions ?
-
Make an argument that childhood obesity is the result of nature or nurture problem ?
-
Explain what approach the efforts will take and explain why the strategy or tactic was considered for the desired outcome for the Latino Community Empowerment Center proposal.
-
Please answer the following questions in an essay What do you think about the aggressive price reduction strategy taht P&G followed? Is market share/volume or profit more important? It seems that...
-
What is EBIT/eps analysis? What information does it provide managers?
-
Length obeys lt+1 = lt - 1.7, with l0 = 13.1 cm. Compose the updating function associated with each discrete-time dynamical system with itself. Find the two-step discrete-time dynamical system. Check...
-
Find and graph the solutions of the following discrete-time dynamical systems for five steps with the given initial condition. Compare the graph of the solution with the graph of the updating...
-
A population of bacteria is increasing at a rate of 1000 / (2 + 3t)0.75 bacteria per hour, starting from a population of 106. Could this sort of growth be maintained indefinitely? When would the...
-
The details in Figure 16.9 relate to D Co. Using that information and appropriate ratios, prepare a financial report on the company. The opening inventory value figures were :135,000 20X1 actual and...
-
A loan is made to a company of $20,000, which is equal to :10,000 at the date of the loan during year 1. The loan is legally denominated in dollars. At the end of year 1, the loan is translated as...
-
The process of expressing a foreign subsidiarys balance sheet in its parents currency is called: A. Currency translation. B. Currency change. C. Currency conversion. D. Currency swap.
Study smarter with the SolutionInn App