Project 62: Mean of Discrete Random Variable

Intro Problem: Suppose a game of chance costs $13 to play.  However, you get paid X dollars after you play the game.  The probability distribution for how much money (X) is paid back.


What is the mean (average) amount of money you would win back (not profit) from playing the game?


For the distribution below, there is a 10% chance that X is 5, a 20% chance that X is 10, a 30% chance that X is 15, and a 40% chance that X is 20.  The calculations are shown below that the mean (or the expected value) for X is 15 (which means your average profit would be $2 since 15 - 13 = 2)

Project 62: Variables x and pX have been initialized.  

x is an array that represents the possible values for x ([5, 10, 15, 20] in the example above).

pX is an array that represents the probability of the corresponding value of x ([.1, .2, .3, .4] in the example above).

Task: Appropriately initialize the value for the variable 'mean' that represents the mean for x.

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