Question: u Problem 4 (60 points). Consecutive integers a) (25 points) Check if a list consists of consecutive integers. Implement the function consecutive(L), which given a


u Problem 4 (60 points). Consecutive integers a) (25 points) Check if a list consists of consecutive integers. Implement the function consecutive(L), which given a list L, checks whether or not L consists of consists of consecu- tive integers. If so, your function should return True. Otherwise, it should return false. See the below test program. If L is not a list, your program should stop with an error message "L must be a list". If L is a list but not all objects in L are integers, your program should stop with an error message "A11 objects in L must be integers". Any correct solution is worth full credit. Test program/output: 3 h print(consecutive([1,2,3])) print (consecutive ([5,6,7])) print(consecutive ([5,6,7,8])) print(consecutive ([5,6,7,8,9,10])) print(consecutive((-2,-1])) print (consecutive ([3])) print(consecutive(()) print(consecutive([2,1,3])) print (consecutive( (3,2,1))) print(consecutive([5,6,8])) print(consecutive([5,5,6,7])) print(consecutive((-2,0])) True True True True True True True False False False False False b) (35 points) Smallest slice cut to make list consecutive. First, review the slicing operator as defined in Programming Assignment 3. In this part, given a list L, we are interested in finding a slice of L of minimal length whose removal from L makes the elements of L consecutive. In particular, implement the function minSliceCut (L), which takes L as input argument and does the following: If I consists of consecutive elements, your function should return the empty list (no need to remove anything from L) Else, your function should return a slice L[i:]+1] whose removal from L makes the elements of L consecutive, for some indices i and ; such that 0 Sisi
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
