#!/usr/bin/env python3
"""Deterministic percentile-bootstrap walkthrough using only Python's stdlib."""

import random
import statistics


DATA = [9, 10, 10, 11, 12, 14, 18]
RESAMPLES = 5_000
SEED = 42


def percentile(sorted_values, probability):
    """Return the nearest indexed empirical percentile for this teaching lab."""
    index = round((len(sorted_values) - 1) * probability)
    return sorted_values[index]


rng = random.Random(SEED)
bootstrap_medians = sorted(
    statistics.median(rng.choices(DATA, k=len(DATA)))
    for _ in range(RESAMPLES)
)

print(f"Stichprobenmedian: {statistics.median(DATA):g}")
print(
    "95%-Perzentilintervall: "
    f"[{percentile(bootstrap_medians, 0.025):g}, "
    f"{percentile(bootstrap_medians, 0.975):g}]"
)
