Apart from the remarks already given about returning instead of printing, and an argument for the number of doors, this code looks good. Instead of looping over the list, you can also use splicing: def check_doors_round_splice(n, num_doors=100): """Check which door is open after n rounds""" doors = [True] * num_doors for step in range(1, min(n, num_doors)): doors[step :: step + 1] = [ not door for door in doors[step :: step + 1] ] return doors