# Exercise 1: the family timeline. BORN_DIED = {"Robert": (1772, 1850), "Alan": (1807, 1865), "David": (1815, 1886), "Thomas": (1818, 1887)} # Part 1: how many of the four were alive in each of these years? for year in (1800, 1820, 1840, 1860, 1880, 1890): alive = [n for n, (b, d) in BORN_DIED.items() if b <= year <= d] print(year, len(alive), alive) # Part 2: ages on the dates the pages give. print("Alan, elected FRSE 1838:", 1838 - 1807) print("Alan, when he became Engineer in Chief in 1843:", 1843 - 1807) print("David, when he moved to the Board in 1853:", 1853 - 1815) print("Thomas, when his first lighthouse (1854) was designed:", 1854 - 1818) print("Robert, when appointed to the Board in 1797:", 1797 - 1772) # Part 3: R. L. Stevenson, whose birth year is only implied (aged 24 in July 1875). BORN_ABOUT = 1875 - 24 for year, event in ((1867, "entered university to study engineering"), (1869, "toured Orkney and Shetland lights"), (1870, "three weeks on Erraid"), (1871, "told his father he wanted a literary career"), (1875, "qualified for the bar")): print(year, "aged about", year - BORN_ABOUT, event) print("his father's age in 1871:", 1871 - 1818) print("years from Robert's appointment to the 1871 decision:", 1871 - 1797) # 1800 1 ['Robert'] # 1820 4 ['Robert', 'Alan', 'David', 'Thomas'] # 1840 4 ['Robert', 'Alan', 'David', 'Thomas'] # 1860 3 ['Alan', 'David', 'Thomas'] # 1880 2 ['David', 'Thomas'] # 1890 0 [] # Alan, elected FRSE 1838: 31 # Alan, when he became Engineer in Chief in 1843: 36 # David, when he moved to the Board in 1853: 38 # Thomas, when his first lighthouse (1854) was designed: 36 # Robert, when appointed to the Board in 1797: 25 # 1867 aged about 16 entered university to study engineering # 1869 aged about 18 toured Orkney and Shetland lights # 1870 aged about 19 three weeks on Erraid # 1871 aged about 20 told his father he wanted a literary career # 1875 aged about 24 qualified for the bar # his father's age in 1871: 53 # years from Robert's appointment to the 1871 decision: 74