Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Instructions - Submit your solutions on Canvas by the deadline displayed online. - Your submission must include a single Python module (file with extension .py)
Instructions - Submit your solutions on Canvas by the deadline displayed online. - Your submission must include a single Python module (file with extension ".py") that includes all of the code necessary to answer the problems. All of your code should run without error. - Problem numbers must be clearly marked with code comments. Problems must appear in order, but later problems may use functions defined in earlier problems. - Functions must be documented with a docstring describing at least (1) the function's purpose, (2) any and all parameters, (3) the return value. Code should be commented such that its function is clear. - You may use standard library modules only (e.g., no numpy or pandas), but you will not receive credit for using a function that exactly duplicates the requested behavior. - All solutions to the given problems must be your own work. If you use third-party code for ancillary tasks, you must cite them. Problem 1 Define a function called cummax (x) that satisfies the following criteria: - Calculates and returns a list giving the cumulative maxima of elements of x - The cumulative max for an element means the max of all previous elements and the current element - The return value should be a list with the same length as x - You may assume x is a list of numbers Examples: In : cummax([1,7,2,11,90,8,100]) Out: [1,7,7,11,90,90,100] In : cummax ([99,99,100,100,22]) Out: [99,99,99,100,100] Problem 2 Define a function called cumsum (x) that satisfies the following criteria: - Calculates and returns a list giving the cumulative sums of elements of x - The cumulative sum for an element means the sum of all previous elements plus the current element - The return value should be a list with the same length as x - You may assume x is a list of numbers Examples: In : cumsum([1,2,3,4,5,6]) Out: [1,3,6,10,15,21]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started