Question: Write a function called sum_i that takes a list of numbers as its argument, and returns the sum of all the numbers in the list.
Write a function called sum_i that takes a list of numbers as its argument, and returns the sum of all the numbers in the list. You should calculate the sum using a for loop. Do not use the built-in sum function (although that's the right thing to do outside of the context of this lab). Put this function in a file called sum.py. We should be able to call this function with s = sum_i(l).
Write another function in the sum.py file called sum_r that calculates the sum recursively. We should be able to call this function with s = sum_r(l).
Write some test code to test your two sum functions out.
Note that:
- You should write tests for all of the functions you write for this lab. Write the tests before you write the code, and put them after the if __name__ == '__main__': line. We're going to import the functions from your files for testing and, if you don't put your tests after this line (and indented to the if block), then it might confuse our testing code. Also, this if good programming practice.
- There are likely to be built-in functions for a number of the things we're asking you to do for this lab. Please don't use them. If you do, you'll get zero points for that part of the assignment, since we want you to write them from scratch (this time).
- The amplitude filter only affects sensor readings beyond a certain threshold. These sensor readings get clipped to the maximum allowed amplitude.
- When you write the variable-width mean filter, you might find array slicing useful. Also, the filtered arrays will be shorter than the input arrays. For a filter with width 3, the filtered lists will be 2 elements shorter than the original list. For a width of 5, it will be 4 shorter, and so on.
- Use Python 3.8
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
