Project 4: Loops (and Booleans and math)

Summary: In this project you will use loops to help calculate how many times you should repeat an activity before the reaching a threshold chance that an event will occur during one of the repetitions. This project will be a computer based project instead of a robot project.

Details:

You may remember from your study of probability that we often have a random event where each succeeding event is unaffected by previous events. For example, if we roll a fair die we have a 1 in 6 (16.67%) chance of rolling a 6.

What if we wanted to know how many rolls it would take to have a good chance of rolling at least one 6?

Each event has a 16.67% chance of rolling the 6. If we have rolled 10 times and gotten 1, 4, 3, 2, 4, ,3, 5, 5, 1, 1 so far, we still have only a 16.67% chance or rolling a 6 on the 11th roll. However, we can calculate how many rolls we much do before we have a 50% or better probability that at least one of the rolls will have been a 6. We do this by calculating how many rolls we need before we have a 6 and then watching for probability to go below 50%.

To caculate the probability that all of the rolls will be of a certian value range we now have an independent probability problem. When calculating probabilities which do not depend on other probabilities we multiply them together. For for the example above: we have an 83.33% chance to roll something other than a 6 when rolling a fair die.

So the chance of not rolling a six on any roll of a fair die:

Number of die
rolls |
Chance that none
of the die rolls is a six |

1 |
83.33% |

2 |
69.44%
(.8333*.8333) |

3 |
57.86% (.8333^{3}) |

4 |
48.22% (.8333^{4}) |

5 |
40.18% (.8333^{5}) |

So from the above table we can see that we cross the 50-50 threshold for rolling a 6 at least once in all of our rolls when we have rolled the die 4 times.

You must ask the use for the following data:

- A text string describing the activity
- The probability of getting the desired result in each event
- the minimum percentage chance of achieving the desired result in
at least one event

- Your program must be commented
- You can have no more than 2 lines outside of your method
- You must store all of the data that the user enters as variables.

Sample output from my implementation. Note that what the program printed is in black text, what I (as the user) typed is in green:

Note - I edited this to show a non-50% threshold on Friday.

What
is the name of your event?Winning the lottery

What
is the probability of a favorable outcome happening in one event? (enter
as a decimal fraction).0001

what
is your minimum threshold for one favorable outcome happening (please
enter as whole number percentage)60

You
asked about Winning the lottery.

You
Said it had a 0.0001 chance to happen

it
will take 9163 events before you have a 60.0% chance to Winning the
lottery

- Add a readme.txt file as a text file in your submission. Your readme
file should contain

- your name
- a brief (one paragraph) description of how you implemented the
project, (what methods did you choose to implement and why)

- anything that is left undone in the project.

submit it to me on Blackboard. Make sure that your submitted file contains your first initial and last name as part of the file name.