Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

A 300N F 30% d 2 m Answered: 1 week ago

Answered: 1 week ago

Question

16.3 Describe the purpose of Canadian labour laws.

Answered: 1 week ago

Question

16.6 Outline the three waysto obtain union recognition.

Answered: 1 week ago

Question

16.5 Describe the five steps in a union organizing campaign.

Answered: 1 week ago