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

image text in transcribedimage 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 In [ ]: def numIncreasingl (L): # Your code here! return In [ ]: print ("Are my sample test cases correct?") print (numIncreasing1 ([5, 2, 1, 3, 4]) = [1,3,4]) print (numIncreasing1 ([2, 1, 4, 5, 6]) = [1,4,5,6]) print (numIncreasingi ([1,2,3,4,4,3,4,5,6,7,7]) = [1,2,3,4]) 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. In [ ]: def numIncreasing2 (3): # your code here! return x In [ ]: print ("Are my sample test cases correct?") print("#1", numIncreasing2 ([5,4,3,2,1]) [5]) print("#2", num Increasing2 ([1,2,3,4,5]) == [1,2,3,4,5]) print("#3", num Increasing2 ([1,2,3,4,4,3,4,5,6,7,7]) == [ 3, 4, 5, 6, 7]) In [ ]: In [ ]: 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 of numbers and a boolean longest which by default is equal to False and will trigger whether numIncreasingl or numIncreasing2 is executed. In [ ]: # Your Code here! In [ ]: In [ ]

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

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

Use a three-step process to develop effective business messages.

Answered: 1 week ago