Project 31: Geometpdf
Suppose you have a 20% chance of winning a particular game of chance. You plan to play until you win. The distribution of games you will play is defined by the geometric distribution with p = .2.
The tree diagram for the first several possibilities is shown below.
If X = the number of games played
P(X = 1) = .2
P(X = 2) = .8*.2 = .16
P(X = 3) = .8*.8*.2 = .128
P(X = 4) = .8^3*.2 = .1024
X can possibly be any number from 1 to infinity but the probabilities continually decrease. The sum of all the probabilities for X still must equal 1.
Project 31: The variables 'p' and 'x' have been initialized.
p represents the probability of success on any trial (.2 in the example shown above)
x represents the number of trials needed to obtain the first success.
Task: Appropriately initialize the value of 'geometpdf' that represents the probability that the number of trials needed is x.
Example: if p = .2 and x = 3, then geometpdf should be .128
**If your code works for 5 test cases, you can enter your e-mail address
Universal Computational Math Methods:
pow(5,2) returns 25.0
abs(-3.0) returns 3
sqrt(49.0) returns 7.0