Kodewick
Start learning →
Mini challenge←→0 / 100

Lift floors

#026Mini challengeLoopsNumbers6 min

A lift starts on floor 1 and stops at the floors in stops, in order. Write floors_travelled(stops) to return how many floors it moves in all, up and down. Basements are negative (-1); with no stops, return 0.

Examples
floors_travelled([5, 2])→7
floors_travelled([1])→0
floors_travelled([])→0
main.py
def floors_travelled(stops):
    floor = 1
    total = 0
    for stop in stops:
        # your code here: add this trip's floors (use abs)
        # to total; then the lift is at stop
        pass
    return total
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.