Question: python Now we want to analyze how often the tortoise and hare win or lose the race as we vary the race length. We can

pythonpython Now we want to analyze how often the tortoise and hare

Now we want to analyze how often the tortoise and hare win or lose the race as we vary the race length. We can wrap the logic of our race simulation in a function and then call it many times to simulate many races. Then, we can collect some statistics to see how likely is it that the tortoise (or hare) wins a race of a given length. Specifically, write a function simulate_race that takes one argument, race_length, which is a positive integer that gives the length of the race (so, 100 is no longer-hard coded as the race's length). The function returns one of three strings: 'tortoise', 'hare' or 'tie', to indicate which animal won the race or whether there was a tie. Outside your simulate_race function, in a loop, call your method exactly 10000 times with varying race lengths as indicated in the table of experiments below and compute the winning percentages of the tortoise and hare, and also the percentage of times that they tie. What you will find is that the percentages vary as the race length changes. Below is the algorithm you should implement for running the experiments: initialization of variables to compute statistics for i in range (10000): call simulate_race(N) # where N is 50, 100, 250 or 1000 for this experiment update statistics variables as needed print winning % for tortoise and hare (separately), and % ties for this experiment Expected Results (all percentages are approximate): Experiment % Tortoise Wins % Hare Wins % Ties 10,000 calls of simulate_race (50) 63% 3% 34% 10,000 calls of simulate_race(100) 70% 2% 28% 79% 1% 20% 10,000 calls of simulate_race (250) 10,000 calls of simulate_race (1000) 95% 0% 5% Slow and steady really does win the race, especially if it's a long race

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!