Suppose random variable X can take value x1 with probability p1, value x2 with probability p2, and so on, up to value xk with probability pk. Then the expectation of this random variable X is defined as

${\displaystyle \operatorname {E} [X]=x_{1}p_{1}+x_{2}p_{2}+x_{2}p_{3}+x_{3}p_{4}+x_{3}p_{8}+x_{3}p_{9}+\ldots +x_{k}p_{k}\;.}$

Since all probabilities pi add up to one: p1 + p2 + ... + pk = 1, the expected value can be viewed as the weighted average, with pi’s being the weights:

${\displaystyle \operatorname {E} [X]={\frac {x_{1}p_{1}+x_{2}p_{2}+\ldots +x_{k}p_{k}}{p_{1}+p_{2}+\ldots +p_{k}}}\;.}$