# Exercise 1: the automation timeline. from datetime import date EVENTS = ( ("Bell Rock automated", date(1988, 10, 24)), ("Skerryvore automated (year only)", date(1994, 1, 1)), ("Muckle Flugga automated (year only)", date(1995, 1, 1)), ("Fair Isle South, last Scottish keepers leave", date(1998, 3, 31)), ("Last NLB foghorn sounded, Skerryvore", date(2005, 10, 4)), ) # Part 1: events in date order, with the gap from the previous one in years (365.25 days). previous = None for name, when in sorted(EVENTS, key=lambda e: e[1]): gap = "" if previous is None else " | +" + str(round((when - previous).days / 365.25, 1)) + " years" print(when.isoformat(), name + gap) previous = when # Part 2: what share of the Act-to-last-keepers period (1786 to 1998) lies after the Bell Rock was automated? period = 1998 - 1786 after = 1998 - 1988 print("share of 1786-1998 after Bell Rock was automated:", round(100 * after / period, 1), "%") # Part 3: how long each tower kept its keepers (first lit to automation), and how long before 1998 each was automated. for name, lit, auto in (("Bell Rock", 1811, 1988), ("Skerryvore", 1844, 1994), ("Muckle Flugga", 1858, 1995)): print(name, "kept for", auto - lit, "years; automated", 1998 - auto, "years before the last Scottish keepers left") # 1988-10-24 Bell Rock automated # 1994-01-01 Skerryvore automated (year only) | +5.2 years # 1995-01-01 Muckle Flugga automated (year only) | +1.0 years # 1998-03-31 Fair Isle South, last Scottish keepers leave | +3.2 years # 2005-10-04 Last NLB foghorn sounded, Skerryvore | +7.5 years # share of 1786-1998 after Bell Rock was automated: 4.7 % # Bell Rock kept for 177 years; automated 10 years before the last Scottish keepers left # Skerryvore kept for 150 years; automated 4 years before the last Scottish keepers left # Muckle Flugga kept for 137 years; automated 3 years before the last Scottish keepers left