Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that takes as input a list of numbers and returns

image text in transcribedimage text in transcribed

Question 1a - Increasing Numbers in List - First Occurence(3 points) Write a function numIncreasing1(L) that takes as input a list of numbers and returns a list of the first sequence within that is increasing order, and has a length of at least 2. If no increasing sequential numbers are found, (ie. the input list is in descending order) then naturally a list of just the first value is returned. Increasing sequence means for a number to be valid it has to be greater than the previous. . [5, 2, 1, 3, 4] returns [1, 3, 4], because only the last 3 are in increasing order [-1, 1, 4, 2, 6) returns [-1, 1, 4] . [5, 1, 8, 9, 10, 100) returns [1, 8, 9, 10, 100] . [4, 1, 2, 3, 4, 2, 4, 6, 8] returns [1, 2, 3, 4] Hint: the break keyword may prove useful to exit a loop def numIncreasing1(L): result = [] for i in range(len(L)): if i == len(L) - 1: result.append(L[i]) else: if L[i] >= L(i + 1]: if result: result.append(L[i]) break else: result.append(L[i]) return result print("Are my sample test cases correct?") print(numIncreasing1([5, 2, 1, 3, 4]) == (1,3,4]) print(numIncreasingl ([2, 1, 4, 5, 6]) == (1,4,5,6]) print(numIncreasingl ([1,2,3,4,4,3,4,5,6,7,7]) == [1,2,3,4]) Are my sample test cases correct? True True True Question 1b: Increasing Numbers in List - Longest Streak (3 points) Now write a function numIncreasing2(L) which applies similar constraints from Question 1a except returns the longest running sequence of increasing numbers L. : def numIncreasing2(s): # your code here! return x print("Are my sample test cases correct?") print("#1", numIncreasing2([5,4,3,2,1]) == [5]) print("#2", numIncreasing2([1,2,3,4,5]) == [1,2,3,4,5) print("#3", numIncreasing2([1,2,3,4,4,3,4,5,6,7,7]) == [ 3, 4, 5, 6, 7]) Question 1c: Increasing Numbers in List - Default Arguments (2 points) Now that you have defined the behavior for both numIncreasingl and numIncreasing2, create a "wrapper function" numIncreasing which takes a list L of numbers and a boolean longest which by default is equal to False and will trigger whether numIncreasingl or numIncreasing2 is executed. : # Your Code here

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

What are the purposes of collection messages? (Objective 5)

Answered: 1 week ago