Your first simulationLesson 03 of 76 · 6 min
Repeat the whole experiment
Build a repeated simulation without mixing inputs from different trials.
A Monte Carlo estimate averages a quantity calculated from random inputs. First define it for one complete trial, then repeat that rule. An indicator is 1 when a condition holds and 0 otherwise; averaging a loss indicator estimates the chance of a loss.
Here each event has attendance, ticket revenue and a fixed venue cost. Profit is revenue minus cost. NumPy applies the arithmetic entry by entry, keeping each count attached to its revenue. A sample mean adds all profits and divides by the number of events. Its target, expectation, is the average weighted by the model's outcome probabilities.
The code also reports percentiles: P10 and P90 are cutoffs with roughly 10% and 90% of outcomes at or below them. P50 is the median, the middle of the ordered outcomes. Finite-sample cutoffs may interpolate between values; the next lesson makes that visible. A positive expected profit can coexist with a substantial loss chance, so inspect both.
In the illustration, denotes profit, E means model expectation and P means probability. reads ‘the chance that profit is negative’.
- Sample together
customers, spending, costs
- Calculate in that world
- Summarise complete worlds
Can an event have positive average profit and still lose money in some trials?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
Estimated mean profit (£): 74.8 Estimated P(loss): 0.1668 Profit percentiles 10/50/90 (£): [-50. 75. 200.]
Read the first result
Read Estimated mean profit (£) alongside Estimated P(loss). The first averages the profit across all events. The second gives the fraction of events with negative profit.
Try an edit
Replace ticket_price, fixed_cost = 25, 900 with ticket_price, fixed_cost = 25, 1000. Select Run Python again. Compare Estimated mean profit (£), Profit percentiles 10/50/90 (£) and Estimated P(loss). What happens to profits when every simulated event pays £100 more?
Scope. Ticket price and venue cost are fixed teaching assumptions. The model omits refunds, variable expenses and selection effects.
Try a fresh case
Two plans have the same mean profit. What else would inform a choice?
Need a hint?
Hint 1
Imagine one plan frequently makes a small gain and occasionally a large loss.
Hint 2
Inspect the distribution relevant to the decision.