Posts Along the Fence

Data with PythonEasy+10 XP+10

Posts Along the Fence

A gardener is putting up a straight fence. It starts at start metres and ends at end metres, and it is split into sections equal sections.

Every section needs a post at each end, and neighbouring sections share a post. So there is a post at the very start, a post at the very end, and posts in between.

Task: write post_positions(start, end, sections) and return the position of every post, in metres, as a plain list, going from start to end.

  • sections is always at least 1.
  • start can be bigger than end. Then the positions go down from start to end.
  • Don't round the positions.

Examples

start = 0
end = 10
sections = 4
returns [0.0, 2.5, 5.0, 7.5, 10.0]
start = 2
end = 3.5
sections = 3
returns [2.0, 2.5, 3.0, 3.5]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run