Kodewick
Start learning →
Basic←→0 / 100

First free seat

#075BasicFunctionsLists4 min

A row of bus seats: True is taken, False is free. Write first_free_seat(seats) to return the number of the first free seat, counting from 1. If every seat is taken, return None.

Examples
first_free_seat([True, True, False, False])→3
first_free_seat([True, True])→None
main.py
def first_free_seat(seats):
    for i in range(len(seats)):
        # your code here: a free seat? return its number i + 1
        pass
    return 0
Ctrl + Enter runs too
Result

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