""""Exercise 2.7 from "A Primer on ..." Generate n + 1 equally spaced coordinates on an interval [a,b]. """ #give some suitable values for a, b, and n n = 10 a = 0 b = 1 #compute the interval length: h = (b - a)/n #a) use a for loop: coor = [] for i in range(n+1): x = a + h * i coor.append(x) print(coor) #b) use a list comprehension: coor2 = [a + h * i for i in range(n+1)] """ Terminal> python coor.py [0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.0] [0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.0] """ """ Comment on the solutions: The solution list comprehension in b) does exactly the same as the loop in a), but using one line instead of 4. Filling a list with values is a very common task, and therefore the list comprehension is offered as an alternative and quicker solution. """