Write a program (called q2.py) to compute the average number of times you need to flip...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program (called q2.py) to compute the average number of times you need to flip a fair coin before you have seen an odd number of heads in a run, followed by a tail. Let H and T represent heads and tails, respectively. Examples of valid runs include HT (ending with 1 head and 1 tail), HHTTTTHHHT (ending with 3 heads and 1 tail), and TTHHTTHHHHTHHHHHHHT (ending with 7 heads and 1 tail). Examples of invalid runs include T (no heads and 0 is an even number), H (must end with T), and HHT (a run of an even number of heads followed by a tail). Before you get started, make sure you understand what the question is asking and then sketch out some examples. Directions for writing your program. a) Your program must have the main() function, which is the main component of your program and the flip_coin() function, which returns either heads or tails to simulate a coin flip. b) Write a Python program to simulate a single trial of the experiment. The result of a single trial is the number of times you need to flip a coin before you have seen an odd number of heads in a run followed by a tail. c) Extend your Python program to run an experiment consisting of n trials. Let n = 10, what is the average number of times the coin was flipped for these 10 trials? d) Run the experiment for 10¹, 10², 10³, 104, 105, and 106 trials. This computation may take a while. Check your output to make sure it makes sense. Do you find the results surprising? Write a program (called q2.py) to compute the average number of times you need to flip a fair coin before you have seen an odd number of heads in a run, followed by a tail. Let H and T represent heads and tails, respectively. Examples of valid runs include HT (ending with 1 head and 1 tail), HHTTTTHHHT (ending with 3 heads and 1 tail), and TTHHTTHHHHTHHHHHHHT (ending with 7 heads and 1 tail). Examples of invalid runs include T (no heads and 0 is an even number), H (must end with T), and HHT (a run of an even number of heads followed by a tail). Before you get started, make sure you understand what the question is asking and then sketch out some examples. Directions for writing your program. a) Your program must have the main() function, which is the main component of your program and the flip_coin() function, which returns either heads or tails to simulate a coin flip. b) Write a Python program to simulate a single trial of the experiment. The result of a single trial is the number of times you need to flip a coin before you have seen an odd number of heads in a run followed by a tail. c) Extend your Python program to run an experiment consisting of n trials. Let n = 10, what is the average number of times the coin was flipped for these 10 trials? d) Run the experiment for 10¹, 10², 10³, 104, 105, and 106 trials. This computation may take a while. Check your output to make sure it makes sense. Do you find the results surprising?
Expert Answer:
Answer rating: 100% (QA)
Heres a Python program named q2py that follows the specified directions import random def flipcoin r... View the full answer
Related Book For
Introductory Statistics Exploring The World Through Data
ISBN: 9780321978271
2nd Edition
Authors: Robert Gould, Colleen Ryan
Posted Date:
Students also viewed these programming questions
-
(a) If log 4 = 2, then x = (b) If log, 9=2, then x =
-
Use the attached "words.txt" file to store the words along with their ranks in an AVL tree. Then provide the user the option to search for any word. If the word exists the program displays the rank...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Find the laurents series f(z)= 1/(z-1)(z-2) (i) |z| <1 (ii) 1 2
-
Magic Flutes has total receivables of $3,000, which represent 20 days' sales. Total assets are $75,000. The firm's operating profit margin is 5%. Find the firm's sales-to-assets ratio and return on...
-
Outline the traditional role of price in the marketing mix.
-
Sawicki Music Supply is a mail-order business that accepts merchandise orders by telephone and mail. All payments must be prepaid with a major credit card. Once an order is received, the item is...
-
Suppose that Wabash completes the house one month later than promised. Inclement weather, which was no ones fault, caused the tardiness. Explain how the court might compute efficient damages.
-
3. [-/0.11 Points] DETAILS SCALCET9 4.1.005. Use the graph to state the absolute and local maximum and minimum values of the function. (Assume each point lies on the gridlines. Enter your answers as...
-
A home network is shown in the following figure and its configurations are shown in the table below. rest of Internet E Router interface D E home network WAN side IP address 130.155.169.8 IP address...
-
Draw a 3-D picture of CH2O showing the bond as well as the four atoms.
-
The total payroll of Waters Company for the month of October 2 0 0 7 was $ 3 6 0 , 0 0 0 . Taxable wages for Social Security ( 6 . 2 % ) were $ 2 7 0 , 0 0 0 Taxable wages for SUTA ( 1 % ) were $ 6 0...
-
From The New York Times, Feb 2 0 , 2 0 0 9 , in a column by Alice Waters and Katrina Heron with that headline: How much would it cost to feed 3 0 million American schoolchildren a wholesome meal? It...
-
What developmental test would you conduct to see how an item would perform under tropical conditions of heat and moisture?
-
Calculate the taxable income adjustment for a U . S . company using transfer pricing at 5 % below the arm\'s length price on $ 1 0 , 0 0 0 , 0 0 0 of goods sold to a Canadian subsidiary.
-
You will thoroughly research your destination about New York City, USA and using secondary data and facts from a variety of sources, and will present this information using the following structure: ...
-
Class, road trips, space exploration, and teams, what could go wrong? Another Discussion to explore some concepts, please make sure to complete both parts. Part 1: Have you ever gone along with a...
-
Subprime loans have higher loss rates than many other types of loans. Explain why lenders offer subprime loans. Describe the characteristics of the typical borrower in a subprime consumer loan.
-
The graph shows the average when a six-sided die is rolled repeatedly. For example, if the first two rolls resulted in a 6 and a 2, the average would be 4. If the next trial resulted in a 1, the new...
-
A study was done on female mice to see whether the amount of light affects the risk of develop ing tumors. Fifty mice were randomly assigned to a regimen of 12 hours of light and 12 hours of dark...
-
A sample of students were questioned to determine how much they would be willing to pay to see a movie in a theater that served dinner at the seats. The male students responded (in dollars): 10, 15,...
-
Fortune Company enters into a risk service agreement with the Chilean government. Fortune pays the government, in U.S. dollars, a \($5,000,000\) signing bonus and also agrees to pay all of the costs...
-
Ibis Company enters into a concession agreement with the British government. Ibis pays the government a \($10,000,000\) (U.S.) signing bonus and agrees to pay the government royalties of 8% of gross...
-
What does a high net wells to gross wells ratio indicate?
Study smarter with the SolutionInn App