Exercise 3 solution (Python) POINTS = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"] def point(bearing): """Nearest of the 16 compass points (each covers 22.5 degrees).""" return POINTS[round((bearing % 360) / 22.5) % 16] def back_bearing(bearing): return (bearing + 180) % 360 def grid_to_magnetic(grid, variation_w): """variation_w is degrees WEST of grid north (negative if east).""" return (grid + variation_w) % 360 def magnetic_to_grid(mag, variation_w): return (mag - variation_w) % 360 for b in (0, 45, 100, 200, 350): print(b, point(b), back_bearing(b)) print(grid_to_magnetic(90, 2), magnetic_to_grid(90, 2)) print(grid_to_magnetic(1, 2), magnetic_to_grid(1, 2)) Output: 0 N 180 45 NE 225 100 E 280 200 SSW 20 350 N 170 92 88 3 359 The modulo (% 360) does the wrap-around: -1 becomes 359 and 480 becomes 120.