Determine the ratio of half pills to all pills


PROGRAMMING ASSIGNMENT

Your simulation has to do with a bottle of vitamin pills. The bottle of pills starts out with N pills. (More on N in a moment.) You need to take one half of a pill each day. Each day, you pull out a pill from the bottle. Assume that any pill is the bottle is equally likely to be selected. If you pull out a whole pill, then you break that pill in half, swallow one of the halves, and put the other half back in the bottle. If you pull out a half pill, then you swallow that half pill.

We are interested in tracking the ratio of half pills to all the pills left in the jar. When you start with a new jar of N whole pills, there are no half pills at all, so the ratio is 0/N. When you get down to the last half pill in the jar (and no whole pills), then the ratio is 1/1. In between, what does that ratio look like? You are going to use random simulation to find out.

Start with a full jar of all whole pills. (Perhaps you should use an array for this; each entry in the array would be able to record if a pill was a half or a whole pill.) Randomly pick one of the pills left in the jar. If that pill is a whole pill, change it to a half pill. If that pill is a half pill, then remove that pill from the jar. (Somehow that array entry should "disappear," and the array should become shorter; there are different ways to do this.)

After each pill is chosen, determine the ratio of half pills to all pills. For a jar holding N whole pills, your simulation will randomly choose a pill 2*N times before the jar is empty.

Format your assignment according to the following formatting requirements:

1. The answer should be typed, double spaced, using Times New Roman font (size 12), with one-inch margins on all sides.

2. The response also includes a cover page containing the title of the assignment, the student's name, the course title, and the date. The cover page is not included in the required page length.

3. Also include a reference page. The Citations and references should follow APA format. The reference page is not included in the required page length.

Solution Preview :

Prepared by a verified Expert
Python Programming: Determine the ratio of half pills to all pills
Reference No:- TGS02987480

Now Priced at $50 (50% Discount)

Recommended (98%)

Rated (4.3/5)