Project 2: 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 instance
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:

Please enter your activity name:Winning the Lottery

Please enter the probability that it will occur in one event:0.0001

please enter your desired minimum probability of the activity

occurring at least once in all of the events: 50

For your activity of Winning the Lottery

with a probability of success of 0.0001 for each event

you need to have 6932 events to have a 50% chance of doing so in one of those 6932 events

- 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.

again zip up your project folder and submit it to me by email. Make sure that your submitted zip file contains your first initial and last name as part of the zip file name.