The most famous Monte Carlo toy: estimate pi by throwing random points in a unit square and counting how many land inside the quarter circle.
import random
def pi_estimate(n):
inside = 0
for _ in range(n):
x, y = random.random(), random.random()
if x * x + y * y < 1.0:
inside += 1
return 4.0 * inside / n
for n in (100, 10_000, 1_000_000):
print(n, pi_estimate(n))
Typical output is something like 3.2, 3.14, 3.1415, with errors in the next digit. The key fact is how the error behaves: it shrinks like 1/sqrt(N). To gain one more correct decimal digit you need 100 times more samples. To gain two, 10000 times.
That sounds terrible, and for a 2D integral it is: simple quadrature rules beat it by a mile. But the rate does not depend on the dimension. A grid with 10 points per axis in 10 dimensions needs 10^10 points, while Monte Carlo still gives 1/sqrt(N). That is why it is the workhorse for high-dimensional integrals in physics, chemistry and graphics.
It also tells you honestly how good your answer is: the spread across independent runs is the error bar. If someone gives you a Monte Carlo number without one, ask for it.