Home > Python >Python Exercise: First Nonconsective Number

First Nonconsective Number

Write a program to print out the first element of a list that is not consecutive. For example, if the input list is [1,2,3,4,8,9], the output should be 8. If the whole list is consecutive, your output should be None. If the list is empty or only have one element, you should also print out None. You can assume the list is sorted in increasing order.

You need login to comment

Solution submitted by Andrew at June 26, 2020, 2:05 a.m.
input = [1, 2, 3, 4, 5, 8, 9] for i in input: number_before_i = i - 1 if i == 1: continue if number_before_i not in input: print(i)

You need login to submit your solution