Finding the first even number
Each version of find_first_even in Listing 1 receives a list of integers. The function should print the first even number and stop. If the list has no even number, it should print No even number found.
find_first_even function. The function finds and prints the first even number in a finite list, or prints No even number found. if the list contains no even number (Question 1).
The list can have any length. Which implementation meets the rule?
TipHint
len(items)returns the number of items, without changing the collection.len([8, 3])is2;len([])is0. For nested lists, it counts the outer items only.range(start, stop, step)supplies integers fromstarttoward, but excluding,stop.stepdefaults to1, andrange(stop)starts at0.list(range(2, 7, 2))is[2, 4, 6];list(range(5, 1, -2))is[5, 3].- A range is empty when the step cannot reach the stop; a zero step raises
ValueError.
listcollects the supplied values in a new list.