A game at the carnival offers these odds: you get to roll a
ten-sided die, and if you roll `RESULT_DESC`,
you make

dollars. Unfortunately,
if you roll anything else, you lose
`MAKE`

dollars.
`LOSE`

How much money do you expect to make (or lose) playing this game?

`$`

The expected value of an event (like playing this game) is average of the values of each outcome. Since some outcomes are more likely than others (sometimes), we weight the value of each outcome according to its probability to get an accurate idea of what value to expect.

There are two events that can happen in this game: either
you roll `RESULT_DESC`, or you don't. So, the
expected value will look like this:

`E = `

(money gained when you roll `RESULT_DESC`)
`\cdot`

(probability of rolling `RESULT_DESC`)
`+`

(money gained when you don't roll `RESULT_DESC`)
`\cdot`

(probability of not rolling `RESULT_DESC`).

The money you gain when you win
is `$`

.
The probability of winning is the probability
that you roll `MAKE``RESULT_DESC`.

This probability is the number of winning outcomes
divided by the total number of
outcomes,

.
`MAKE_FR`

The money you gain when you lose is
`$ -`

(since you actually lose money). The probability that
you lose is the probability that you don't roll
`LOSE``RESULT_DESC`.

This probability must be
`1 - `

.
`MAKE_FR` = `LOSE_FR`

So, if we take the average of the amount of money you make
on each outcome, weighted by how probable each outcome is,
we get the expected amount of money you will make:
`(`

`MAKE`\cdot`MAKE_FR`) +
(-`LOSE`\cdot`LOSE_FR`) =
$`ANS_F` = $`ANS`.

If you roll a `SIDES`-sided die, what is the expected
value you will roll?

The expected value of an event (like rolling a die) is average of the values of each outcome. To get an accurate idea of what value of expect, we weight the value of each outcome according to its probability.

In this case, there are `SIDES` outcomes:
the first outcome is rolling a 1, the second outcome is
rolling a 2, and so on. The value of each of these outcomes
is just the number you roll.

So, the value of the first outcome is 1, and its
probability is `\dfrac{1}{`

.
`SIDES`}

The value of the second outcome is 2, the value of
the third outcome is 3, and so on. There are
`SIDES` outcomes altogether, and each of them
occurs with probability
`\dfrac{1}{`

.
`SIDES`}

So, if we average the values of each of these outcomes,
we get the expected value we will roll, which is

.
`SUM` =
`mixedFractionFromImproper(ANS_N,SIDES,true,true)`

You decide you're only going to buy a lottery ticket if the
expected amount of money you will get is positive. Tickets
cost `$`

, and you get
`COST``$`

if you win. The odds of
winning are `PRIZE``1`

in

,
meaning that you will win with probability
`ODDS`

.
`ODD_F`

Should you buy a ticket for this lottery?

- Yes, the expected value is positive.
- No, the expected value is negative.

The expected value of an event (like buying a lottery ticket) is the average of the values of each outcome. In this case, the outcome where you win is much less likely than the outcome that you lose. So, to get an accurate idea of how much money you expect to win or lose, we have to take an average weighted by the probability of each outcome.

As an equation, this means the expected amount of money
you will win is
`E = `

(money gained when you win)
`\cdot`

(probability of winning) `+`

(money gained when you lose)
`\cdot`

(probability of losing)
.

Let's figure out each of these terms one at a time. The
money you gain when you win is your winnings minus the
cost of the ticket, `$`

(you may find the math easier
if you `PRIZE` -
$`COST`**don't** simplify this).

From the question, we know the probability of winning is

.
`ODD_F`

The money you gain when you lose is actually negative,
and is just the cost of the ticket,
`-$`

.
`COST`

Finally, the probability of losing is ```
(1 -
```

(you may find the math
easier if you `ODD_F`)**don't** simplify this).

Putting it all together, the expected value is
`E = ($`

`PRIZE` - $`COST`)
(`ODD_F`) + (-$`COST`)
(1 - `ODD_F`) = ` $ \dfrac{`

.
`PRIZE`}
{`ODDS`} - $ \cancel{\dfrac{`COST`}
{`ODDS`}} - $`COST` +
$ \cancel{\dfrac{`COST`}{`ODDS`}} =
$`fraction(PRIZE,ODDS,true,true)` -
$`COST`

`$`

is
`fraction(PRIZE,ODDS,true,true)` -
$`COST``PRIZE/ODDS - COST > 0 ? "positive" : "negative"`.

So, we expect to `PRIZE/ODDS - COST > 0 ? "make" : "lose"` money by buying a lottery ticket, because
the expected value is `PRIZE/ODDS - COST > 0 ?
"positive" : "negative"`.