# How Epidemics Spread 1, Exercise 3: a point-source outbreak # 80 guests share one dinner (assumed). Each falls ill with probability 0.4 # (assumed attack rate). The time from the meal to onset is 6 hours plus 21 hours # times the sum of two random numbers (a bell-ish shape between 6 and 48 hours; # assumed). Use random.Random(7). Count onsets in 6-hour bins # after the meal and draw the curve; then say whether the shape looks like a # point-source or a propagated outbreak, and why. import random rng = random.Random(7) guests, attack_rate = 80, 0.4 onsets = [] for _ in range(guests): if rng.random() < attack_rate: onsets.append(6 + 21 * (rng.random() + rng.random())) print("cases:", len(onsets), f"({len(onsets) / guests:.0%} of guests)") print(f"first onset {min(onsets):.1f} h, last onset {max(onsets):.1f} h") for lo in range(0, 48, 6): n = sum(1 for t in onsets if lo <= t < lo + 6) print(f"{lo:2d}-{lo + 6:2d} h {n:2d} " + "#" * n) # Output when run: # cases: 39 (49% of guests) # first onset 11.3 h, last onset 41.3 h # 0- 6 h 0 # 6-12 h 3 ### # 12-18 h 9 ######### # 18-24 h 8 ######## # 24-30 h 13 ############# # 30-36 h 2 ## # 36-42 h 4 #### # 42-48 h 0