Intro to Computer Science
Project 4: Loops (and Booleans and math)
Due: At
11:59pm Wed Oct 11th
Thursday Oct 12th (To give you the chance to ask all those questions you
had on Monday during the holiday)
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% (.83333)
|
4
|
48.22% (.83334)
|
5
|
40.18% (.83335)
|
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.
The Program:
Your Job is to write a program which implements this property to calculate
when a set of low probability events crosses a user designed threshold.
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
then you must calculate the expected number of events it will take to
achieve your proscribed level of probability that at least one desired
result will occur.
Additional Restrictions on your program for good programming
- 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
Submitting:
- 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.