Question: A strictly increasing consecutive subsequence is a part of a sequence in which every element is strictly greater than the previous element. Because strictly increasing

A strictly increasing consecutive subsequence is a part of a sequence in which every element is strictly greater than the previous element. Because strictly increasing consecutive subsequence is a bit long, we will call this a streak. For example, in the sequence (1,5,2,4,7,2), the subsequences (1,5) and (2,4,7) are streaks. (Of course, by definition, any subsequence of a streak is also a streak.)(2,4,7) is the longest streak among all streaks of that input sequence.
Below is a function that takes as argument a sequence of numbers, and it aims to return the length of the longest streak of the input sequence:
def longest_streak(seq):
i=0
counter=1
narray=[]
#base case
if len(seq)==0:
return(0)
while i < len(seq)-1:
if seq[i]< seq[i+1]:
counter=counter+1
i=i+1
else:
narray.append(counter)
counter=1
i=i+1
if len(narray)==0:
return(counter)
else:
return(max(narray))
However, the function above is not correct.
(a) Provide an example of argument, of correct types, that makes this function return the wrong answer or that causes a runtime error. The argument must be a sequence of numbers.
(b) Explain the cause of the error that you have found, i.e., what is wrong with this function. Your answer must explain what is wrong with the function as given. Writing a new function is not an acceptable answer, regardless of whether it is correct or not.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!