floors = [5, 2, 8]

current = 1
total_distance = 0

for floor in floors:
    total_distance += abs(floor - current)
    current = floor

total_distance += abs(current - 1)

print(total_distance)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: